Posts: 2,020
Threads: 24
Joined: Jun 2002
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Posts: 1,956
Threads: 65
Joined: Jun 2003
Oooops, Toonski, I get a "page cannot be found".
*****
Posts: 788
Threads: 53
Joined: Nov 2002
I think you should take my advice, in windows you can't get much higher precision then the orginal 1/18 sec.
oship me and i will give you lots of guurrls and beeea
Posts: 2,020
Threads: 24
Joined: Jun 2002
http://www.betterwebber.com/test2/TIMWIN.ZIP - sorry. damn that unix and its case insensitivity. and that works, and works only in windows.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Posts: 1,407
Threads: 117
Joined: Dec 2002
Toonski:
A fine link, seav's timer does'nt work at all in W2000.
Well, I don't think my method is so bad. What are 5 seconds compared to the eternity?
And for execution speed fluctuations, If you let the program loop for 5 seconds, you are averaging the execution time. It does'nt happen if you execute the test code only once.
Antoni
Posts: 788
Threads: 53
Joined: Nov 2002
The thing with your way antoni is that you're polling on timer each loop. That's bad, even if timer was an empty function which it's not that far call alone would slow down allot. And if you're not using ffix it's horrible slowing down the loop 200%-400% i could imagine. I'm not going to repeat myself after this. But if you want accurate timing the code i posted is it.
oship me and i will give you lots of guurrls and beeea
Posts: 2,020
Threads: 24
Joined: Jun 2002
antoni, that link doesnt go to seav's timer, it goes to a library robert claypool gave me that has routines that set up a timer device with some windows interrupt. I know refreshing the timer with outs has problems in windows. you can test for dos or windows, and use the better if you were tricky.
i]"I know what you're thinking. Did he fire six shots or only five? Well, to tell you the truth, in all this excitement, I've kinda lost track myself. But being as this is a .44 Magnum ... you've got to ask yourself one question: 'Do I feel lucky?' Well, do ya punk?"[/i] - Dirty Harry
Posts: 1,956
Threads: 65
Joined: Jun 2003
I still like Antoni's approach. It's simple, and I know exactly what's going on. If I use some fancy timing function from a library, I don't know what the heck is going on, and I have to assume it's ok.
Let's not lose sight of the issue here which is to compare two distinct blocks of code to see which is faster. Inserting these blocks of code into a loop which is incrementing a counter and which uses TIMER should not be a problem. The overhead of the counter incrementing and the invocation of TIMER is going to be applied to both blocks of code. We don't need to know exactly how fast they run --- we're only interested in which is faster.
*****
Posts: 1,407
Threads: 117
Joined: Dec 2002
And if you wanted to know the exact speed you could run an empty loop and substract the time used by that loop.
Antoni
Posts: 1,407
Threads: 117
Joined: Dec 2002
This is the function I use to test my code speed.
In odd calls Timeit starts the timer and in even calls it returns -1 and results are printed if the test time is passed .
First couple of calls must be done in an empty loop, to calibrate the program, the results obtained will be substracted from the times of the true tests.
Code:
'this is a timing function to benchmark your routines
DECLARE FUNCTION timeit% ()
x% = -1234
'This call is to calibrate empty loop.
'Empty loop time is substracted from the real loops timer
dummy% = timeit
DO
LOOP UNTIL timeit
'--go for first test--------------------
'this starts the timer
dummy% = timeit
DO
'example of tested code
x1% = SGN(x%): x2% = ABS(x%)
'if 5 secs passed stop timer and display the results
LOOP UNTIL timeit
PRINT cubic#
'go for second test---------------------
'start the timer again
DO
'example of tested code
IF x% > 1 THEN x1% = 1: x2% = x% ELSE x1% = -1: x2% = -x%
'if 5 secs passed stop timer and display the results
LOOP UNTIL timeit
'You can add here as many test loops as you want
a$ = INPUT$(1)
END
FUNCTION timeit%
STATIC TIME!, timing%, counter!, testnum%, emptytime#
CONST testlen = 5 'seconds to loop for each test
IF timing% THEN
IF TIMER < TIME! THEN
counter! = counter! + 1
EXIT FUNCTION
ELSE
IF testnum% = 1 THEN
emptytime# = 1000000# / counter!
PRINT USING "Empty loop time ###,###.### us: Loops #,###,###"; emptytime#; counter!
ELSE
thistime# = 1000000# / counter! - emptytime#
PRINT USING "Test nr ## time ###,###.### us: Loops #,###,###"; testnum% - 1; thistime#; counter!
END IF
timing% = 0
timeit% = -1
END IF
ELSE
counter! = 0
testnum% = testnum% + 1
timing% = NOT timing%
PRINT
IF testnum% > 1 THEN
PRINT "Starting Test "; testnum% - 1; ". It will last "; testlen; " seconds."
ELSE
PRINT "Starting Empty loop Calibration. It will last "; testlen; " seconds."
END IF
TIME! = TIMER
DO
LOOP UNTIL TIMER > TIME!
TIME! = TIMER + testlen
END IF
END FUNCTION
Antoni