help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

(no subject)


From: Mark Goldman
Subject: (no subject)
Date: Wed, 18 May 2005 10:06:36 -0700

I am running the following code on a Sun Solaris  OS 5.7 machine.

I am compiling it with both g++ 2.95 and g++ 3.3.2, using the command:

g++ -O3 -o z z.cc

where z.cc is the following:


#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;

main(int argc, char** argv) {

   int i = 1;
   double d1 = 2.3;
   double d2 = 3.4;

   ofstream ofstr("zout");

   for (int counter = 0; counter < 300000; counter++) {
      ofstr << i << d1 << d2 << '\n';
   }

   ofstr.close();

}

for g++ 2.95, the executable is 786 kilobytes, and the job takes 2.3 seconds to run for g++ 3.32, the executable is only 13 kilobytes, but the job takes 9.5 seconds to run

Thus g++ 2.95 is 4 times faster than g++ 3.3.2.

Is this normal?



When I try using <cstdio> instead of <iostream>:

#include <cstdio>

using namespace std;

main(int argc, char** argv) {

   int i = 1;
   double d1 = 2.3;
   double d2 = 3.4;

   FILE* ofstr = fopen("zout", "w");

   for (int counter = 0; counter < 300000; counter++) {
      fprintf(ofstr, "%d%.1f%.1f\n", i, d1, d2);
   }

   fclose(ofstr);

}

for g++ 2.95. the executable is only 6 kilobytes, but takes 3.4 seconds to run
for g++ 3.32, the executable is only 7 kilobytes, but takes only 2.3 seconds to run


Summary:
for g++ 2.95, the <iostream> version produces a large executable, but it runs even quicker than the <cstdio> version

for g++ 3.3.2, the <iostream> version produces a similar size executable as the <cstdio> version, but runs EXTREMELY slow (4 times slower than the g++ 2.95 <iostream> version or the g++ 3.3.2 <cstdio> version)

I would like to use the <iostream> libraries for g++ 3.3.2, but how can I speed up the execution time? I tried compiling the g++ 3.3.2 <iostream> version using the -static keyword, but it only took a second
of the execution time while creating an enormous 6000 kilobyte executable.

Any suggestions?





reply via email to

[Prev in Thread] Current Thread [Next in Thread]