This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
iostream performance
- To: egcs-bugs at cygnus dot com
- Subject: iostream performance
- From: Bob Glickstein <bobg at zanshin dot com>
- Date: Tue, 9 Feb 1999 11:28:47 -0800 (PST)
- Organization: Zanshin Inc., Marin County, CA
- Reply-To: Bob Glickstein <bobg at zanshin dot com>
Hi! This isn't quite a bug, but: recently I did some tests comparing
the performance of this C program
int c;
while ((c = getchar()) != EOF)
putchar(c);
with this C++ program
int c;
while ((c = cin.get()) != EOF)
cout << static_cast<char>(c);
Here are the results in seconds, copying a 9 Mb file to /dev/null:
Pentium PowerPC
---- -----
C, non-optimized 6.377 1.94
C, optimized 6.139 1.181
C++, non-optimized 12.683 16.53
C++, optimized 10.698 10.339
(The Pentium has egcs 2.92.25 installed; the PowerPC, egcs 2.90.25.)
According to strace, the main loop of all versions makes precisely the
same system calls; further, compiling the C version with the C++
compiler produces C-like performance. So the performance hit seems to
be in the iostream implementation.
My questions are: why is there such a performance penalty for using
iostreams; is there any way to work around that; and is there any
prospect for better performance in future versions?
Many thanks in advance.