Strange optimization results

Jonathan Wakely jwakely.gcc@gmail.com
Sun Apr 10 22:20:00 GMT 2011


2011/4/10 Дмитрий Оксенчук:
> I have tested performance of std::string compare methods and get
> strange results. With -O2 optimization std::string::compare 30 times
> faster then operator==. With -Os optimization operator== 5 times
> faster then std::string::compare. Is this bug or feature?
>
> Full table (time for 10000000 comparisons in seconds):
>                        -O0             -O1             -O2             -O3             -Os
> compare         1.069   1.057   0.029   0.025   1.072
> operator==      0.461   0.990   0.980   1.022   0.201

Did you run the tests more than once and average the results? Your
test code has no timing measurements in it, what are you measuring?
The entire time for the executable to run?  That includes time for the
OS to create and run a new process, and will depend how busy the
system is, so could have very little to do with the code in the
executable.



More information about the Gcc-help mailing list