Mail Archives: djgpp/1998/03/05/00:34:32
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 -