4 ms·
What is the Real World impact of a change like this? From the sample code, the person is building some kind of GUI with widgets. How many extra assembly instr
by throwaway2037 2y ago
What is the Real World impact of a change like this? From the sample code, the person is building some kind of GUI with widgets. How many extra assembly instructions are performed as a result of this particular push_back vs emplace? In my experience with C++ and Qt, the amount of execution time spent building the GUI trivial compared to the paint (or business logic).
The amount of time spent on these trivial issues in C++ never ceases to amaze me about the "C++ crowd". How many more "C++: Back to the basics" talks do we have to sit through? I await the C++ programmers whom will quickly reply to this post: "But, performance!"
That said, this author has appeared many times before on HN. He is an excellent writer.
- valicord 2y agohttps://en.wiktionary.org/wiki/widget#Noun https://en.wiktionary.org/wiki/widget#Noun "A placeholder name for an unnamed, unspecified, or hypothetical manufactured good or product, typically as an example for purposes of explaining concepts."
- db48x 2y agoIt only has a measurable cost if the constructor is slow, and for most types that won’t be the case.
- nercury 2y agoIf someone spent their time learning their tools, they will make better choices when writing the code without any additional time cost. There are two variants of very similar code. Both do the same thing, both are readable and maintainable. The difference is not primarily in performance, it's in quality of craft.
- otabdeveloper4 2y agoemplace_back is mostly used for objects that are constructed only once and forbidden from being copied. It's not so much a performance tool as a tool for consistency guarantees.