In general the second one is faster because the first might involve one or more reallocations of the underlying array that stores the data. This can be aleviated with the reserve function like so:
vector<int> numbers; numbers.reserve(10); for (int i = 0; i < 10; ++i) numbers.push_back(1); This would be almost identicalclose in performance to your 2nd example since reserve tells the vector to allocate enough space for all the elements you are going to add so no reallocations occur in the for loop. The only difference would be thatHowever push_back will also likely involve incrementing an end pointer orstill has to check whether vector's size variable which is very cheapexceeds it's current capacity and increment the value indicating the size of the vector so this will still be slightly slower than your 2nd example.