delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/04/14:16:20

From: "Martin Ambuhl" <mambuhl AT tiac DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: [Q]Computing speed in C++
Date: Wed, 4 Mar 1998 14:13:46 -0500
Organization: Honors Bridge Club
Lines: 56
Message-ID: <6dk947$kaf@news-central.tiac.net>
References: <34FCB769 DOT 42BEF1A8 AT gong DOT snu DOT ac DOT kr> <34FD3174 DOT 2401F904 AT gong DOT snu DOT ac DOT kr>
NNTP-Posting-Host: p10.ts3.newyo.ny.tiac.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019