This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: slow execution speed when compared against visual c++
- From: Oscar Fuentes <ofv at wanadoo dot es>
- To: gcc-help at gcc dot gnu dot org
- Date: 04 Jan 2003 16:05:38 +0100
- Subject: Re: slow execution speed when compared against visual c++
- References: <3E16827A.30309@virtualmaterials.com>
Marco Satyro <marco@virtualmaterials.com> writes:
> 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 math.
>
> Could you provide me with any clues about this problem?
[snip]
> // test speed for floating point calcs
>
> #include <stdio.h>
> #include <time.h>
> #include <stdlib.h>
> #include <math.h>
>
> int main(void)
> {
> clock_t start, finish;
>
> start = clock();
>
> printf("\n start...\n");
>
> for (double i = 0; i < 1e7; i++)
> {
> double val = (double)i + 0.01;
> val = log(val);
> val = exp(val);
> val = sin(val);
> val = cos(val);
> val = tan(val);
> val = log10(val);
> val = i;
> val = sqrt(val);
> val = pow(val, 4.567);
> }
Maybe MSVC++ optimizes out those repeated assignments to 'val'. It
could be that its optimizer is good enough to note that the repeated
assignments to 'val' are useless due to the 'val = i;' assignment near
the end of the loop.
GCC's floating point performance is not as good as MSVC++. However, a
480x factor is so big that you can bet something is not behaving as
you think. Please keep in mind that simple tests like the above rarely
are good indicators of the actual performance a real-world complex
application will achieve.
If you insist on using that simple test, do something like this:
double val1, val2, ...
val1 = val2 = ... = 0
/* begins the loop */
val1 += log(val);
val2 += exp(val);
val3 += sin(val);
...
/* ends the loop */
printf ("%f %f ...", val1, val2, ...);
This will force the compiler to produce executable code for performing
all the calculations.
I guess you are using some MinGW gcc release (it would be a good thing
to know the versions of the compilers you are using). IIRC gcc version
3.x is better than 2.x for floating point.
Possibly there are some switches besides -O3 that could improve
floating point performance. You could try asking on the MingW mailing
list.
[snip]
--
Oscar