delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/05/00:34:32

From: demandrd AT compusmart DOT ab DOT ca (Demandred)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: [Q]Computing speed in C++
Date: Thu, 05 Mar 1998 01:13:54 GMT
Message-ID: <34fdfbb5.4215087@news.compusmart.ab.ca>
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: remote1017.compusmart.ab.ca
Lines: 41
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Wed, 04 Mar 1998 19:48:20 +0900, Bum-Seok Hyun
<dominic AT gong DOT snu DOT ac DOT kr> was heard to ramble:

>Scott Warner wrote:
>
[snip]
>Let me first thank you for your kind concern.
>
>Main body of my test code is
>
>for(int i=1 ; i<10001 ; i++)
>   for(int j=1 ; j<10001 ; j++)
>       for(int k=1 ; k < 11 ;  k++)  sum += i;
>
>Above code is ,of course , for C++.
>
>In C code, I just moved variable definitions
>into the first line of the code.
>Like,
>
>int i,j,k;
>float sum;
>
>That's all.

That would do it!  In the C version, you're declaring three ints and a
float.  In the C++ version, you're declaring int i once, int j 10001
times, int k (1001^2) 1002001 times, and float sum **1100220011
times**.  (Your stack must hate you =)

That would tend to account for the extra thirty or so seconds.

>I don't think that makes musch difference between C++ and C.

Well, umm...


--
Demandred, Lord of the 32-bit Registers
Check out my game at:
http://www.nnetis.ca/~matt/dogfight.html

- Raw text -


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