T
tom fredriksen
Sorry, for some reason I was thinking my results where in minutes. But
it makes sense now
After some head banging I realise that your number are comparatively
correct.
I find the reason to be twofold 1) cpu 2) compiler/system. Athlon is
quite different and newer than a K6 that should explain some of it. The
other reason is because of the cpu and system it optimises differently.
Leading to the athlon/linux test to behave differently than on a k6/win.
If you replaced the rand expression with a guaranteed integer
expression, the numbers between the two tests where equal. So there is
something in the rand causing it to behave radically different. I looked
at the generated assembler and I didn't find it was that different, but
still the execution was different... interesting.
Another thing I just noticed is that if I create the program to contain
both version at the same time, there is no difference, both are at 7
seconds. But if I remove the float version its back up to 1 seconds. I
am going mad now...
There is definitely something going on with the rand statement causing
it to affect the entire program.
data[c]=1.0+(unsigned int) (2000000000.0*rand()/(RAND_MAX+1.0));
The complete code is at the bottom, I fixed it to be like yours.
Can anybody test this code on an equivalent system and a one that is
different but newer than k6? My system is Linux 2.6.3 with gcc 3.3.2
Linux NG? never heard of it.. do explain...
/tom
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
void test_orig()
{
unsigned int total = 0;
int count = 65500;
unsigned int data[count];
struct timeval start_time;
struct timeval end_time;
int c,d;
double t1, t2;
for(c=0; c<count; c++) {
data[c]=1.0+(unsigned int) (2000000000.0*rand()/(RAND_MAX+1.0));
}
gettimeofday(&start_time, NULL);
for(d=0; d<50000; d++) {
for(c=0; c<count; c++) {
total += data[c];
}
}
gettimeofday(&end_time, NULL);
t1=(start_time.tv_sec*1000)+(start_time.tv_usec/1000.0);
t2=(end_time.tv_sec*1000)+(end_time.tv_usec/1000.0);
printf("Elapsed time (ms): %.6lf\n", t2-t1);
printf("Total: %u\n", total);
}
void test_int()
{
unsigned int total = 0;
int count = 65500;
unsigned int data[count];
unsigned int data2[count];
struct timeval start_time;
struct timeval end_time;
int c,d;
double t1, t2;
for(c=0; c<count; c++) {
data2[c] = data[c];
}
gettimeofday(&start_time, NULL);
for(d=0; d<50000; d++) {
for(c=0; c<count; c++) {
total += data[c];
}
}
gettimeofday(&end_time, NULL);
t1=(start_time.tv_sec*1000)+(start_time.tv_usec/1000.0);
t2=(end_time.tv_sec*1000)+(end_time.tv_usec/1000.0);
printf("Elapsed time (ms): %.6lf\n", t2-t1);
printf("Total: %u\n", total);
for(c=0; c<100; c++) {
printf("data2: %u ", data2[c]);
}
printf("\n");
}
int main(int argc, char *argv[])
{
/* test_orig(); */
test_int();
return(0);
}
it makes sense now
Gcc v3.41 yes, but DJGPP uses it's own libc. I keep forgetting that DJGPP
has it's own libc which is different from GNU libc. That could _easily_ be
a factor. Also, CPU speeds increase by roughly a factor of 2 per generation
(2), so 1/4 of 44 ~ 11.
(2 runs, w/loop)
gcc -O2
Elapsed time (ms): 42790.000000
Elapsed time (ms): 43450.000000
(2 runs, no loop)
gcc -O2
Elapsed time (ms): 44160.000000
Elapsed time (ms): 44050.000000
(2 runs, w/loop)
gcc -Wall -O2 -D_LARGEFILE64_SOURCE -std=gnu99
Elapsed time (ms): 44600.000000
Elapsed time (ms): 43340.000000
(3 runs, no loop)
gcc -Wall -O2 -D_LARGEFILE64_SOURCE -std=gnu99
Elapsed time (ms): 39600.000000
Elapsed time (ms): 42840.000000
Elapsed time (ms): 40970.000000
After some head banging I realise that your number are comparatively
correct.
I find the reason to be twofold 1) cpu 2) compiler/system. Athlon is
quite different and newer than a K6 that should explain some of it. The
other reason is because of the cpu and system it optimises differently.
Leading to the athlon/linux test to behave differently than on a k6/win.
If you replaced the rand expression with a guaranteed integer
expression, the numbers between the two tests where equal. So there is
something in the rand causing it to behave radically different. I looked
at the generated assembler and I didn't find it was that different, but
still the execution was different... interesting.
Another thing I just noticed is that if I create the program to contain
both version at the same time, there is no difference, both are at 7
seconds. But if I remove the float version its back up to 1 seconds. I
am going mad now...
There is definitely something going on with the rand statement causing
it to affect the entire program.
data[c]=1.0+(unsigned int) (2000000000.0*rand()/(RAND_MAX+1.0));
The complete code is at the bottom, I fixed it to be like yours.
Can anybody test this code on an equivalent system and a one that is
different but newer than k6? My system is Linux 2.6.3 with gcc 3.3.2
It might be time to try a linux NG to see if someone with a similar system
to yours is getting the same issue...
Linux NG? never heard of it.. do explain...
/tom
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
void test_orig()
{
unsigned int total = 0;
int count = 65500;
unsigned int data[count];
struct timeval start_time;
struct timeval end_time;
int c,d;
double t1, t2;
for(c=0; c<count; c++) {
data[c]=1.0+(unsigned int) (2000000000.0*rand()/(RAND_MAX+1.0));
}
gettimeofday(&start_time, NULL);
for(d=0; d<50000; d++) {
for(c=0; c<count; c++) {
total += data[c];
}
}
gettimeofday(&end_time, NULL);
t1=(start_time.tv_sec*1000)+(start_time.tv_usec/1000.0);
t2=(end_time.tv_sec*1000)+(end_time.tv_usec/1000.0);
printf("Elapsed time (ms): %.6lf\n", t2-t1);
printf("Total: %u\n", total);
}
void test_int()
{
unsigned int total = 0;
int count = 65500;
unsigned int data[count];
unsigned int data2[count];
struct timeval start_time;
struct timeval end_time;
int c,d;
double t1, t2;
for(c=0; c<count; c++) {
data2[c] = data[c];
}
gettimeofday(&start_time, NULL);
for(d=0; d<50000; d++) {
for(c=0; c<count; c++) {
total += data[c];
}
}
gettimeofday(&end_time, NULL);
t1=(start_time.tv_sec*1000)+(start_time.tv_usec/1000.0);
t2=(end_time.tv_sec*1000)+(end_time.tv_usec/1000.0);
printf("Elapsed time (ms): %.6lf\n", t2-t1);
printf("Total: %u\n", total);
for(c=0; c<100; c++) {
printf("data2: %u ", data2[c]);
}
printf("\n");
}
int main(int argc, char *argv[])
{
/* test_orig(); */
test_int();
return(0);
}