When you use push_back like in your code, you construct a temporary, THEN pass it to push_back, which makes a copy of the object to put in the vector, and then push_back ends and returns to your code where the temporary is not needed anymore, so it is destroyed. The construct-copy-destruct is very slow.
When you use emplace_back like I suggested, you construct a temporary, THEN pass it to emplace back, which moves the contents of the temporary into the vector, and then emplace_back ends and returns to your code where the temporary is not needed anymore, so it is destroyed. The construct-move-destroy is much more efficient.
The output you are seeing is perfectly normal, though because of the copies it is indeed inefficient.
I recommend you look up move semantics.
Bugsplatter wrote: |
---|
I'm still using 2010 |
THis could refer to anything, but I am assuming you mean Microsoft's Visual C++ 2010 IDE? If so, I feel very very sorry for you.