Hi, all
Frank suggested using the CPU timer, and I agree that it's a much better benchmark than the clock timer (I keep discovering gems in gpc.pas!). But I'm getting identical results from the two timers:
var time1, time2 : longCard; dummy, cpu1, cpu2 : integer; ... time1 := GetMicroSecondTime; dummy := 0; cpu1 := GetCPUTime(dummy);
for i := 1 to big do j := randNorm(0.0, 1.0);
dummy := 0; cpu2 := GetCPUTime(dummy); time2 := GetMicroSecondTime; writeln('Time for ', big:1, ' randNorms: ', ((time2-time1)*0.000001):7:2, ' seconds, ', (cpu2-cpu1):5, ' cpu seconds.'); ...
A note in gpc.pas says that the argument to GetCPUTime can be null and is then ignored.
When the computer is idle except for this program, I get: Time for 100000000 randNorms: 171.03 seconds, 171 cpu seconds.
When I'm checking email, opening files, etc., I get: Time for 100000000 randNorms: 202.29 seconds, 202 cpu seconds.
What am I doing wrong here - or is GetCPUTime not working?
Toby
On Mon, 1 Mar 2004, Toby Ewing wrote:
Hi, all
Frank suggested using the CPU timer, and I agree that it's a much better benchmark than the clock timer (I keep discovering gems in gpc.pas!). But I'm getting identical results from the two timers:
var time1, time2 : longCard; dummy, cpu1, cpu2 : integer; .. time1 := GetMicroSecondTime; dummy := 0; cpu1 := GetCPUTime(dummy);
for i := 1 to big do j := randNorm(0.0, 1.0);
dummy := 0; cpu2 := GetCPUTime(dummy); time2 := GetMicroSecondTime; writeln('Time for ', big:1, ' randNorms: ', ((time2-time1)*0.000001):7:2, ' seconds, ', (cpu2-cpu1):5, ' cpu seconds.'); ..
When the computer is idle except for this program, I get: Time for 100000000 randNorms: 171.03 seconds, 171 cpu seconds.
The for-loop is cpu-intensive. You might try repeating the tests with: time <name-of your-program>
then change the for-loop: for i = 1 to not-so-big do begin j := randNorm(0.0, 1.0); writeln( i, ' ',j ); end;
You should get some interesting numbers.
Russ
p.s. couldn't find "randNorm" so used "random( 1000 )"
When I'm checking email, opening files, etc., I get: Time for 100000000 randNorms: 202.29 seconds, 202 cpu seconds.
What am I doing wrong here - or is GetCPUTime not working?
Toby
Toby Ewig wrote:
Hi, all
Frank suggested using the CPU timer, and I agree that it's a much better benchmark than the clock timer (I keep discovering gems in gpc.pas!). But I'm
My experience was that real time is more accurate then CPU time. The resolution of CPU time is limited by frequency of timer interrupt (10 ms on i386 Linux) and there are random (and sometimes systematic) errors that may chenge result by few ticks. So to get good results one have to use pretty long times. On many modern machines (notably Pentium or better) real time clock have much higher acuraccy (of order of microseconds). I have found that on unloaded machine I get repeatable results even with submillisecond run times. In general real time seem to be much more repeatable then CPU time.
getting identical results from the two timers:
<snip>
When the computer is idle except for this program, I get: Time for 100000000 randNorms: 171.03 seconds, 171 cpu seconds.
When I'm checking email, opening files, etc., I get: Time for 100000000 randNorms: 202.29 seconds, 202 cpu seconds.
What am I doing wrong here - or is GetCPUTime not working?
That looks very strange. Other processes may increase your CPU time (if you have heavy cache trashing), but to trash the cache some CPU time have to happen outside your process. I have seen systematic errors, but nothing of that magnitude...
Waldek Hebisch wrote:
My experience was that real time is more accurate then CPU time.
On a single-user system with no background processes running, this might be true. (At least one of the conditions is usually not fulfilled when I'm doing something ... ;-)
When the computer is idle except for this program, I get: Time for 100000000 randNorms: 171.03 seconds, 171 cpu seconds.
When I'm checking email, opening files, etc., I get: Time for 100000000 randNorms: 202.29 seconds, 202 cpu seconds.
What am I doing wrong here - or is GetCPUTime not working?
That looks very strange. Other processes may increase your CPU time (if you have heavy cache trashing), but to trash the cache some CPU time have to happen outside your process. I have seen systematic errors, but nothing of that magnitude...
BTW (to OP), which system is this?
Frank
Frank Heckenbach wrote:
Waldek Hebisch wrote:
My experience was that real time is more accurate then CPU time.
On a single-user system with no background processes running, this might be true. (At least one of the conditions is usually not fulfilled when I'm doing something ... ;-)
When the computer is idle except for this program, I get: Time for 100000000 randNorms: 171.03 seconds, 171 cpu seconds.
When I'm checking email, opening files, etc., I get: Time for 100000000 randNorms: 202.29 seconds, 202 cpu seconds.
What am I doing wrong here - or is GetCPUTime not working?
That looks very strange. Other processes may increase your CPU time (if you have heavy cache trashing), but to trash the cache some CPU time have to happen outside your process. I have seen systematic errors, but nothing of that magnitude...
BTW (to OP), which system is this?
I'm running in a "cmd" shell under win2000.
I thought there was a "time" utility that worked in DOS/win, but I haven't managed to find it. But I would prefer to put it into the code, if I can.
Toby