(C Code) could you run this for me please

Soldato
Joined
15 Nov 2008
Posts
5,060
Location
In the ether
Hi Guys,

I'd post this in programming but you lot probably already have the right set up to run this quickly. It won't blow up your computer or anything. You'll need to have a gcc installed.

Call it program.c
compile with
gcc -ansi -Wall program.c
and run with
./a.out

and if you could post the results here I'd appreciate it (only got access to one machine at the moment :o). Should take less than a minute on a decent machine (that's why it took over two on this **** piece).

Thanks

Dstat
P.S. it's just comparing 3 ways of using an integer:) But I think I've got "speedstep" or whatever it's called ****ing it up on this laptop


#include <stdio.h>
#include <time.h>
#define NUM 2;
main(){


register int a = 2;
int b = 2;
time_t mytime = time(0);
int p[5] = {1,2,3,4,5};
int i=0;
int j=0;

time_t startTime = time(0);
for(j=0;j<900000000;j++){
for(i=1;i<5;i++){
p=p[i-1]*a;
}
}
time_t endTime = time(0);
printf("Testing registers\n");
printf("Start Time is %d \n",startTime);
printf("End Time is %d \n",endTime);
i=0;
j=0;

startTime = time(0);
for(j=0;j<900000000;j++){
for(i=1;i<5;i++){
p=p[i-1]*b;
}
}
endTime = time(0);
printf("Testing raw integer\n");
printf("Start Time is %d \n",startTime);
printf("End Time is %d \n",endTime);


i=0;
j=0;
startTime = time(0);
for(j=0;j<900000000;j++){
for(i=1;i<5;i++){
p=p[i-1]*NUM;
}
}
endTime = time(0);
printf("Testing DEFINED integer\n");
printf("Start Time is %d \n",startTime);
printf("End Time is %d \n",endTime);

}
 
steve@PC:~/Programming/C$ ./a.out
Testing registers
Start Time is 1253561865
End Time is 1253561881
Testing raw integer
Start Time is 1253561881
End Time is 1253561896
Testing DEFINED integer
Start Time is 1253561896
End Time is 1253561913
 
Code:
[jack@tmain t]$ ./a.out 
Testing registers
Start Time is 1253566671 
End Time is 1253566681 
Testing raw integer
Start Time is 1253566681 
End Time is 1253566691 
Testing DEFINED integer
Start Time is 1253566691 
End Time is 1253566700
 
If you want to compare performance, you should split the test into three separate programs, to prevent cache warm-up, etc.
You should also turn on optimizations (-O2 or -O3), and prevent the compiler optimizing away the loops by e.g. printing an element of the p array after the loops.
As-is, this test probably isn't very helpful.
 
Back
Top Bottom