5 ms·
The performance test is comparing apples to oranges, since the StringBuilder is filled only once and the timing is taken only on the .Join() method. If you rep
by ot 13y ago
The performance test is comparing apples to oranges, since the StringBuilder is filled only once and the timing is taken only on the .Join() method.
If you replace the code
start = clock();
for (int i = 0; i < loops; ++i) {
std::wstring result2 = tested.ToString();
}
double secsBuilder = (double) (clock() - start) / cps;
with
start = clock();
for (int i = 0; i < loops; ++i) {
StringBuilder<wchar_t> wide;
wide.Add(tested2.begin(), tested2.end()).AppendLine();
std::wstring result2 = wide.ToString();
}
double secsBuilder = (double) (clock() - start) / cps;
the results go from
Accumulate took 0.134847 seconds, and ToString() took 0.014123 seconds.
The relative speed improvement was 854.804%
to
Accumulate took 0.146171 seconds, and ToString() took 0.099802 seconds.
The relative speed improvement was 46.461%
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).
- jemfinch 13y ago> 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.
- dkersten 13y agoAnd 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.