Free Lunch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The following code appears to provide a free lunch. Can someone try this on their systems
to see if they get similar results?

Thanks,
Cino

//                                        Free Lunch
//
//Mind boggling code in Gcc 3.4.4. incrementing a variable in a loop runs 20 times faster than just
//an empty loop.
//System: p4 2.53 ghz xp pro
//Compile data
//C:\gcc\examples>f:\gcc\bin\g++ COUNTgcc.c -o COUNTgcc.exe -s -O3 -mtune=pentium4
//C:\gcc\examples>g++ -dumpversion
//3.4.4

#include <windows.h>
#include <stdio.h>
#define timer GetTickCount()/1000.0
float t1,t2;
long count1(long);
long count2(long);
int main()
{
t1=timer;
printf("%s%u\n"," j = ",count1(2000000000));
t2=timer;
printf("%s%f\n"," Sec = ",t2-t1);
printf("\n");
t1=timer;
printf("%s%u\n"," y = ",count2(2000000000));
t2=timer;
printf("%s%f\n"," Sec = ",t2-t1);

getchar();
return 0;
}
long count1(long i)
{
long j;
for(j=1;j<=i;j++)
{
}
return j;
}

long count2(long i)
{
long j,y=0,s=0;
for(j=1;j<=i;j++)
{
y+=1;
//s+=7;
}
return y;
}


output

j = 2000000001
Sec = 0.984375

y = 2000000000
Sec = 0.046875



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux