This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/16401] New: ostringstream in gcc 3.4.x very slow for big data


Hello, 
 
I'm using ostringstream to write big amounts of data (some 10MB). For simplicity the 
data is written as single bytes. For gcc 3.3.x the time per character needed is almost 
constant for different amounts of data. But for 3.4.x this time increases dramatically:  
the time / char - ratio for 10 MB is 8 times that for 1 MB. 
 
This performance-decrease does not happen to string-concatenation using +=. 
 
Appended is an example program that has a switch to measure the performance of 
both string and ostringstream. 
 
I'm using linux 2.4.20 with SuSE 8.2 on a pentium 4, 512 MB Ram, 2.4 GHz. The gcc 
is 3.4.1, but the results are similar to 3.4.0. gcc -v tells:  
 
configured with: ../gcc-3.4.1/configure --enable-threads=posix --prefix=/usr 
--with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man 
--libdir=/usr/lib --enable-languages=c,c++,f77,objc,java,ada --disable-checking 
--enable-libgcj --with-gxx-include-dir=/usr/include/g++ --with-slibdir=/lib 
--with-system-zlib --enable-shared --enable-__cxa_atexit i486-suse-linux 
Thread-Modell: posix 
gcc-Version 3.4.1 
 
///// compile with ///// 
g++ -O2 -march=pentium4 -Wall -o strstream_t strstream_t.cpp 
 
///// strstream_t.cpp ///// 
 
/// 0: use ostringstream 
/// 1: use string 
#define STR_ONLY 0 
 
#include <iostream> 
 
#include <sys/time.h> 
#include <sys/resource.h> 
#include <unistd.h> 
 
#if STR_ONLY 
# include <string> 
#else 
# include <sstream> 
#endif 
 
using namespace std; 
 
static double time2dbl(long sec, long usec) 
{ 
  return sec + usec * 1e-6; 
} 
 
/// gives time in seconds and microseconds 
static void FineTimeInt(unsigned int *sec, unsigned int *musec) 
{ 
  static struct timeval last_tv; 
  struct timeval tv; 
 
  gettimeofday(&tv,NULL); 
 
  last_tv = tv; 
  *sec = tv.tv_sec; 
  *musec = tv.tv_usec; 
} 
 
/// gives time in seconds 
static double FineTime(void) 
{ 
  unsigned int sec, musec; 
  FineTimeInt(&sec, &musec); 
  return time2dbl(sec, musec); 
} 
 
int main() 
{ 
  double oldr = 1; 
  for(int n = 1; n <=  10000000; n *= 10) { 
#if STR_ONLY 
    string str; 
#else 
    ostringstream str; 
#endif 
    double t0 = FineTime(); 
    for(int i = 0; i < n; i++) { 
#if STR_ONLY 
      str += char(i); 
#else 
      str << char(i); 
#endif 
    } 
    double t1 = FineTime(); 
    double t = t1 - t0; 
#if STR_ONLY 
    double l = str.length(); 
#else 
    double l = str.str().length(); 
#endif 
    double r = t / l; 
    cout << n << " " << l << " " <<  t << " " << r << " " <<  r / oldr << endl; 
    oldr = r; 
  } 
}

-- 
           Summary: ostringstream in gcc 3.4.x very slow for big data
           Product: gcc
           Version: 3.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jan at planet dot de
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16401


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]