Re: STL Slow - VS2005
"-ephi" <-ephi@discussions.microsoft.com> skrev i meddelandet
news:4232B407-5C77-4AFA-9310-B8A05B49C361@microsoft.com...
Hi,
I'm the developer who created these tests.
"Jerry Coffin" wrote:
The first and most crucial question to ask of any benchmark is how
accurately this benchmark represents real-world workloads. Unless
the
benchmark is quite close to real-world usage, it's meaningless --
and
even if it's fairly close, it can still be entirely meaningless (if
the
differences between "fairly close" and "real world" make a big
difference in performance).
Yes, but I am microbenchmarking a small subset of the STL string
implementation only. Most real world apps will have bigger
bottlenecks to
deal with and these benchmarks will not matter much. The benchmarks
do point
to a more efficient implementation in STLPort.
string s ;
for ( int i = 0 ; i < 100000000; ++ i ) {
s += " " ;
Test was meant to benchmark the performance when the string must do
new
allocations. This was an easy way to get at that.
But in practice it unfortunately doesn't measure that. The operator +=
probably maps to
append(String, traits_type::length(String));
In my implementation I got about a 10 times speedup by adding the
special case
basic_string& append(const value_type* _String, size_type _StringSize)
{
if (_StringSize == 1)
push_back(*_String);
else
...
}
So, you are measuring one *very* specific optimization of the standard
library implementation. Adding a single space character could be
s += " ";
s += ' ';
s.push_back(' ');
s.append(" ");
s.append(1, ' ');
You are just measuring the first one.
Bo Persson