Serious performance problems

Loren James Rittle rittle@latour.rsch.comm.mot.com
Mon Jul 16 17:53:00 GMT 2001


In article < 995012534.16287.3.camel@elgrande > you write:

> My quick tests seem to indicate a 30x slowdown in the new iostreams.

> #include <iostream>
>
> using namespace std;
>
> int main(int argc, char *argv[])
>    {
>    cin >> cout.rdbuf();
>    }

Here is what I see on i386-*-freebsd4.2 (-O2 -static):

; time a.out-g++2.95 </kernel >/dev/null
     5r     3.6u     0.0s       a.out
; time a.out-g++3.0 </kernel >/dev/null
    33r     7.3u    11.0s       a.out
; time a.out-g++mainline </kernel >/dev/null
     5r     4.0u     0.1s       a.out

[However, please note that I do have a submitted yet unapplied
 performance patch related to over-agressive flushing of C-layer
 output streams in my mainline tree at the moment.]

When I add this line:

    ios::sync_with_stdio (false);

[Please see the C++98 standard and/or section 21.8 of _TC++PL-SE_.]

as the first thing done in main(), I see these results:

; time a.out-g++2.95 </kernel >/dev/null
     0r     0.3u     0.0s       a.out
; time a.out-g++3.0 </kernel >/dev/null
     4r     2.8u     0.0s       a.out
; time a.out-g++mainline </kernel >/dev/null
     4r     2.8u     0.0s       a.out

There is one (possibly disturbing?) thing I found related to this
performance issue.  The number of bytes written for a.out-g++2.95 is
exactly the number found in /kernel (2499086).  The number of bytes
written for a.out-g++3.0 and a.out-g++mainline is 2430567.  Thus, I
speculate that the C++ library wasn't looking at/processing the bytes
being transfered in the old implementation.  I don't know if it should
be processing/removing bytes under the current implementation, but it
clearly is.  The time to do that processing (perhaps locale-related?)
is non-trivial.

Here was the smallest data set I could generate (assume bash quoting):

; echo $'\377\010'|a.out-g++2.95|od -c
0000000  377  \b  \n                                                    
0000003
; echo $'\377\010'|od -c
0000000  377  \b  \n                                                    
0000003
; echo $'\377\010'|a.out-g++mainline|od -c
0000000  377  \n                                                        
0000002

Regards,
Loren



More information about the Libstdc++ mailing list