-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace Vector push_back() vs emplace_back() #175
Comments
Thank you for your excellent suggestion. |
A new performance check will be great (I am very curious about the measurement) |
Thanks heaps for the PR, but I want to check it out before committing it.
Indeed, and me too! 😜 |
I've just run the simple benchmark test that's in ConsoleDemo1 and I'm sorry to say there's been no measurable change in performance 😞. Unless you can demonstrate otherwise, I'm not inclined to change the existing code. Anyhow, I appreciate the feedback and maybe you can find performance improvements somewhere else? 🤞🙏. |
Interesting. Thanks. |
push_back and emplace_back in C++
Push_back: Push_back adds a new element at the end. It first creates a temporary object by calling a constructor.
Emplace_back: It also Inserts a new element at the end. It does not create a temporary object. The object is directly created in the vector. Due to this, the efficiency is increased.
The difference in the efficiency of push_back and emplace_back depends on the type of our vector. If the vector is a built-in type, there is no difference between the efficiency of push_back and emplace_back. If the vector type is class or struct, emplace_back is more efficient than push_back.
see also:
https://www.codingninjas.com/codestudio/library/vector-push_back-vs-emplace_back#:~:text=Push_back%3A%20Push_back%20adds%20a%20new%20element%20at%20the,vector.%20Due%20to%20this%2C%20the%20efficiency%20is%20increased.
The text was updated successfully, but these errors were encountered: