Re:Performance Improvement with the StringBuilder for C++
by jemfinch on Friday September 06, 2013 @12:55PM
(#6341371)
> std::list is an awful container...You should never use it, unless you really know what you are doing
To put a finer point on that: you should use std::list iff you need to splice (or insert into the middle) in constant time.
Re:Performance Improvement with the StringBuilder for C++
by dkersten on Friday September 06, 2013 @03:12PM
(#6342103)
And order is important and splicing is a common task and the list is large enough or copying elements expensive enough that other schemes are not viable...
Linked lists really have a very narrow use case.
If you replace the code
with the results go from to Much less impressive.Furthermore, the author is not using any of the standard techniques to avoid memory allocations in C++ (such as reusing the same container with .clear() instead of creating a new one each time), that would improve even more the performance.
Besides, despite what the author says, std::list is an awful container (one allocation per element, terrible locality, ...). You should never use it, unless you really know what you are doing (for example, see Stroustrup's recent talks).