Amazing but unexpected behavior of a simple C test

 
Post new topic   Reply to topic    CPU-World.com forums Forum Index -> Modern CPUs - upgrades, overclocking and troubleshooting
View previous topic :: View next topic  
Author Message
Cef
Guest





PostPosted: Thu Mar 29, 2012 10:59 am    Post subject: Amazing but unexpected behavior of a simple C test Reply with quote

Hello

Some time ago I made this simple C speed test:

#include <stdio.h>
#include <math.h>
#include <time.h>

extern double sqrt(double);

void compute( void ){
long n;
double k;

for(n=1;n<750000000;++n){
k = n * 3;
k = sqrt(k) / 2;
}
printf("Test ended\n");
return;
}

void main()
{
clock_t start_time, end_time;
double Time, S,E,Tics;

start_time = clock();

compute();
end_time = clock();
S = start_time;
E = end_time;
Tics = CLOCKS_PER_SEC;
Time = (E - S) / Tics;
printf( "Execution time was %f seconds\n", Tiempo) ;
}

At that time I had the Pentium Dual-Core E5400 2.70GHz. The
time execution was 21.20 seconds. What amazed me was that
I ran it in four Linux (Ubuntu) terminals simultaneously
and the times where: 21.20, 21.17, 21.28 and 21.22 seconds.
Question ONE: Why are those times equals or almost equal to
the test I ran in just one terminal alone?

Recently I upgrade to an Intel Core i3-2120 3.30GHz and the
time in one terminal was sightly more: 23.39 seconds.
Question TWO: Why, if this microprocessor has a faster clock
and better technology.

Running this test in four terminals simultaneously give the
expected result to me, longer times because the OS has to
give slides of power to each terminal, about 34 seconds each one.
However, when I disabled the Hyper Threading feature from
the BIOS (the MB is an Asrock H67M-GE motherboard), the four
terminal test behave like the E5400, that is, all the times
around 23.39 seconds.
Question THREE: Did you expect this? Why?

Thank you very much in advance.

Regards,

Carlos
Back to top
Display posts from previous:   
Post new topic   Reply to topic    CPU-World.com forums Forum Index -> Modern CPUs - upgrades, overclocking and troubleshooting All times are GMT - 5 Hours
Page 1 of 1
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Powered by phpBB © 2001 phpBB Group