[Bug c/20429] New: Free Lunch?
hillcino368 at hotmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Mar 11 18:46:00 GMT 2005
Hi,
S1: Dell Diminsion p4 2.533ghz 2gig ram
Batch
g++ %1.c -o %1.exe -O3 -mtune=pentium4
g++ -dumpversion
S2: Dell xps p3 1.0ghz 256 meg ram
g++ %1.c -o %1.exe -O3 -mtune=pentium3
g++ -dumpversion
The following code gives much faster timings for 2000000000 vs 1000000000.
Is this a free-lunch or is it a bug? Also it appears that including the
line sum+=1 causes the loop to run faster on the p4. At any rate Gcc runs
about 30% faster than Lcc. Also the loop
MOV EAX,2000000000
L1:
DEC EAX
JNZ L1
A386 takes 1.21 sec on S1
Gcc is truly a code optimizer.
[CODE]
#include <stdio.h>
#include <time.h>
#define timer clock()/1000.0
float t1,t2;
unsigned long count (unsigned long);
unsigned long billions = 2000000000;
int main()
{
t1=timer;
printf("%u",count(2000000000));
//printf("%u",count(1000000000));
//printf("%u",count(billions));
t2=timer;
printf("%s%G\n"," Sec = ",t2-t1);
getchar();
return 0;
}
unsigned long count (unsigned long i)
{
unsigned long sum;
sum=0;
for(;i>0;i--)
{
sum +=1;
}
return sum;
}
[/CODE]
Test 2000000000
S1 output -> 2000000000 Sec = 0.031
S2 output -> 2000000000 Sec = 0.18
Test 1000000000
S1 output -> 1000000000 Sec = 0.484
S2 output -> 1000000000 Sec = 2.103
Test billions = 2000000000
S1 output -> 2000000000 Sec = 1.218
S2 output -> 2000000000 Sec = 4.486
Test sum +=1; commented out for 2000000000
S1 output -> 0 Sec = 0.984
S2 output -> 0 sec = 4.186
Test sum +=1; commented out for billions = 2000000000
S1 output -> 0 Sec = 0.968
S2 output -> 0 sec = 4.155
--
Summary: Free Lunch?
Product: gcc
Version: 3.4.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: hillcino368 at hotmail dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20429
More information about the Gcc-bugs
mailing list