floating point exponential in math.h is slow

Antonio Suriano suriano@sns.it
Wed Jan 23 14:21:00 GMT 2002


Hi

i've found a strange feature of g++ compiler 
i've written a c++ code that makes a lot of operations in floating point 
using math.h and i realized that linux g++/gcc with -O3 is much slower than 
visual c++/borland on windows.. same machine
the benchmark is the result of an average of course and in linux it runs in 
consolle without loading X at the start...
i think that exponential calculation in floating point is slower as 
developed in math.h (the program gives partial results so i can see wich is 
the slowest)
the code is very simple and the operations are few so it cannot be called a 
benchamrk but i think it is important

machine is duron 900 256 mega ram

linux kernel 2.4.10-4GB
gcc 2.95.3

results (average on 10 measures):
visual c++ 6.0:73.3 sec
borland :      76.4 sec
gcc      :     94.7 sec
visual c++ code running in a wine session: 78 sec (!!!!!!!) 

this is the code:

#include <stdio.h>
#include <math.h>
#include <time.h>

void main ()


{

double a,b,c;
long int d,i;
long int start, stop, durata;

i=0;
d=100000000;
a=0;
c=0;

start=time (NULL);
for (i=0; i<=d ; i++)
{
        b=exp(a);
        c= c + b/float(d);
        a= a + 1/float(d);

}
printf ("%d\n",d);
printf ("%f\n",a);
printf ("b=%f\n",b);
printf ("%d\n",i);
printf ("%f\n",c);
for (i=0; i<=d ; i++)
{ 
        b=log(a+1);
        c= c + b/float(d);
        a= a + 1/float(d);
 
}
printf ("%d\n",d);
printf ("%f\n",a);
printf ("b=%f\n",b);
printf ("%d\n",i);
printf ("%f\n",c);
for (i=0; i<=d ; i++) 
{
        b=cos(a);
        c= c + b/float(d);
        a= a + 1/float(d);

}
printf ("%d\n",d);
printf ("%f\n",a); 
printf ("b=%f\n",b);
printf ("%d\n",i);
printf ("%f\n",c);
stop= time (NULL);
durata= stop - start; 
printf ("il programma e' durato %d secondi \n", durata);
}
-- 
Antonio Suriano

suriano@sns.it
ICQ uin: 144361087
-- 
Antonio Suriano

suriano@sns.it
ICQ uin: 144361087



More information about the Gcc-bugs mailing list