[Patch] Fix istream::ignore + minor things
Martin Sebor
sebor@roguewave.com
Tue May 25 18:08:00 GMT 2004
Paolo Carlini wrote:
> Damour, James A wrote:
>
>> Would your ignore code benefit from using __builtin_expect (see example
>> below)?
>>
>> - if (__n != numeric_limits<streamsize>::max())
>> + if (__builtin_expect(__n !=
>> numeric_limits<streamsize>::max(),1))
>>
>>
> Thanks for the suggestion. The evidence about the benefits of
> __builtin_expect is actually rather thin, however.
FWIW, in my experiments with gcc 3.2 on IPF, the gcc optimizer
didn't seem to take any noticeable advantage of the hint. The
same function (hand-coded strcmp) performed exactly the same
without the hint as it did with it (regardless of whether the
hint was right or wrong).
Intel C++ 8.0, on the other hand, seemed to be quite sensitive
to the hint. The same function performed up to 40% better with
the correct hint than with the wrong one. In cases where the
optimizer was able to correctly assign branch probabilities
without the presence of the hint it made little difference;
where it wasn't the hint was a big help.
Incidentally, in the optimized cases the code generated by icc
ran between 25% and 50% faster than the same code generated by
gcc.
The test program and the output generated by gcc -O3 and icc
-O3 are in the attached archive. The output from running the
test cases is here:
$ (g++ t.cpp -O3; n=0; while [ $n -ne 6 ]; do echo "### $n ###"; time
./a.out 1000000 $n; n=`expr $n + 1`; done)
### 0 ###
real 0m7.301s
user 0m7.216s
sys 0m0.005s
### 1 ###
real 0m8.616s
user 0m7.218s
sys 0m0.006s
### 2 ###
real 0m7.273s
user 0m7.201s
sys 0m0.001s
### 3 ###
real 0m8.428s
user 0m8.248s
sys 0m0.001s
### 4 ###
real 0m8.330s
user 0m8.237s
sys 0m0.005s
### 5 ###
real 0m8.288s
user 0m8.226s
sys 0m0.004s
$ (icc t.cpp -O3; n=0; while [ $n -ne 6 ]; do echo "### $n ###"; time
./a.out 1000000 $n; n=`expr $n + 1`; done)
### 0 ###
real 0m3.199s
user 0m3.108s
sys 0m0.002s
### 1 ###
real 0m4.172s
user 0m4.133s
sys 0m0.002s
### 2 ###
real 0m3.144s
user 0m3.115s
sys 0m0.002s
### 3 ###
real 0m7.293s
user 0m7.215s
sys 0m0.004s
### 4 ###
real 0m8.306s
user 0m8.261s
sys 0m0.002s
### 5 ###
real 0m6.268s
user 0m6.220s
sys 0m0.002s
Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: br-test.tar.gz
Type: application/x-gzip
Size: 11533 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20040525/a6d538a6/attachment.bin>
More information about the Libstdc++
mailing list