Mail Archives: djgpp/1998/03/04/14:16:20
Bum-Seok Hyun wrote in message <34FD3174 DOT 2401F904 AT gong DOT snu DOT ac DOT kr>...
|> > So I made a test for comparing computing time.
|> > The result is
|> > c code : 21 sec
|> > c++ code : 57 sec
I can't get this kind of difference...
I implemented your test as:
#include <stdio.h>
#include <time.h>
int main(void)
{
clock_t start = clock();
double sum;
#if defined(__GNUG__) && defined(SLOWMODE)
for(int i=1 ; i<10001 ; i++)
for(int j=1 ; j<10001 ; j++)
for(int k=1 ; k < 11 ; k++) sum += i;
#else
int i, j, k;
for(i=1 ; i<10001 ; i++)
for(j=1 ; j<10001 ; j++)
for(k=1 ; k < 11 ; k++) sum += i;
#endif
printf("Time = %f\n",(double)(clock()-start)/CLOCKS_PER_SEC);
return 0;
}
Then, using this script:
echo "C compilation..."
gcc -O2 -m486 a.c -o a.exe
a
echo "C++ compilation of C code..."
gxx -O2 -m486 a.C -o a.exe
a
echo "C++ compilation with SLOWMODE..."
gxx -O2 -m486 -DSLOWMODE a.C -o a.exe
a
The following output is produced:
C compilation...
Time = 50.989011
C++ compilation of C code...
Time = 51.043956
C++ compilation with SLOWMODE...
Time = 54.835165
- Raw text -