$ g++ -v
Configured with: ../gcc-3.4.2/configure --prefix=/tools/pkg/gcc/3.4.2 --enable-
languages=c,c++ --with-ld=/bin/ld --with-as=/bin/as --disable-threads
Thread model: aix
gcc version 3.4.2
/// t.cc
#include <iostream>
#include <cstdio>
using namespace std;
int main( int argc, char** argv )
{
std::ios_base::sync_with_stdio( false );
int count = 100000;
if( argc > 1 )
for( int i = 0; i < count; ++i )
std::cout << (double)i;
else
for( int i = 0; i < count; ++i )
{
char buf[50];
sprintf( buf, "%g", (double)i );
std::cout << buf;
}
return 0;
}
///
$ g++ -o t t.cc
$ time t > /dev/null
real 0m0.07s
user 0m0.05s
sys 0m0.00s
$ time t cout > /dev/null
real 0m4.22s
user 0m2.60s
sys 0m1.60s
The std::ios_base::sync_with_stdio( false ); seems to have no effect.
Note: On i686-pc-linux-gnu, both cout and sprintf/<<(char*) take the same time.
Using the AIX system g++ 2.9-aix51-020209, there is also no difference (both
are fast).
--
Summary: streaming doubles is very slow compared to sprintf
Product: gcc
Version: 3.4.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: joerg dot richter at pdv-fs dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: powerpc-ibm-aix5.2.0.0
GCC host triplet: powerpc-ibm-aix5.2.0.0
GCC target triplet: powerpc-ibm-aix5.2.0.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19642