slow execution speed when compared against visual c++

Andrea 'fwyzard' Bocci
Sat Jan 4 16:39:00 GMT 2003

At 23.43 03/01/2003 -0700, Marco Satyro wrote:
>Dear GCC Help
>I am considering converting a very large project from Visual C++ to GCC.
>This project does lots of scientific computations and therefore the 
>execution speed is very important. I am doing the development on a Pentium 
>4 running Windows XP, and I wrote a little program to test the execution 
>speed. I installed gcc using cygwin and wrote the program using the 
>bloodshed IDE. The program and makefile are attached
>I set the optimization flag to -O3, but I am getting an execution speed 
>480 times slower than when I use Visual C++. It seems like gcc is using 
>some kind of floating point emulation instead of using the actual hardware 

I made some tests using both MSVC++ 6.0 (w/ latest patches) and cygwin GCC 3.2.
I'm using Windows XP SP1 on an Athlon 900.
The test file is attached below.

MSVC++ used with standard options, with
Release mode
Optimized for speed
Optimized for pentium pro

GCC used with
1.) -lm -O2 -std=c99
2.) -lm -O2 -std=c99 -march=athlon -mfpmath=sse -malign-double -mmmx -msse 
3.) -lm -O2 -std=c99 -march=athlon -mfpmath=sse -malign-double -mmmx -msse 
-m3dnow -ffast-math

GCC used targetting mingw with the above plus

I run the resultin exe 10 times, taking the faster values

MSVC++  1.772 s
GCC 1.) 2.774 s
GCC 2.) 2.673 s
GCC 3.) 2.303 s
MinGW 1.)       2.804 s
MinGW 2.)       2.693 s
MinGW 3.)       2.323 s

So it looks that using ctgwin or mingw is about the same, about 30% slower 
than MSCV++ generated code. Ops...
BTW, I tried removing the -lm switch from the last MinGW builds, and the 
run time jumped up to 7.080 s ! Don't ask...

So, GCC doesn't look to SO good rom this small benchmark, but not SO bad,. 

-------------- next part --------------
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>

int main(void)
   clock_t start, finish;

   start = clock();

   double sum = 0.0;
   for (double i = 0; i < 1e6; i++)
      double val = (double) i + 0.01;
      sum += log(val);
      sum += exp(val);
      sum += sin(val);
      sum += cos(val);
      sum += tan(val);
      sum += log10(val);
      sum += sqrt(val);
      sum += pow(val, 4.567);

   finish = clock();

   double duration = (double)(finish - start) / CLOCKS_PER_SEC;

   printf ("sum is %.3f\n", sum);
   printf ("Elapsed time = %.3f s\n", duration);
   return 0;

More information about the Gcc-help mailing list