This performance test is a concise program which measures the time it takes to perform arbitrary operations. The operations can any command or function that you need to time the execution of. The code being timed is executed no more than once per second.
The snippet is used by copying and pasting code or a function reference into one of the test functions. For example, two methods could be compared by calling method 1 in the supplied function called Test1(), and the second in Test2(). The time taken to execute is displayed output to screen.
If you use any 3D commands, the CLS call in the program loop will need to be omitted so that the screen does not flicker. Each test loop should be changed to the amount of iterations you need to time; for instance, use FOR i = 1 to 10, for ten iterations; all test should compare the same amount of iterations.
The
Matrix1 utilities library supplies a special timer used in this snippet.
`%Project Title%
`%Source File Name%
`======================
`======================
` Performance test {Performance snippet v1.0}
Sync On : Sync Rate 0
Global t as Double Integer
Global m
Global n = 1
Dim a$(100)
Do
CLS
n = 1
Set Cursor 0, 0
//-------------------------
m = Timer()
t = HTimer()
Test1()
t = HTimer() - t
m = Timer() - m
PrintResult("Test 1 time: ")
//-------------------------
//-------------------------
m = Timer()
t = HTimer()
Test2()
t = HTimer() - t
m = Timer() - m
PrintResult("Test 2 time: ")
//-------------------------
//-------------------------
//-------------------------
//-------------------------
m = Timer()
t = HTimer()
Test3()
t = HTimer() - t
m = Timer() - m
PrintResult("Test 3 time: ")
//-------------------------
//-------------------------
//-------------------------
//-------------------------
m = Timer()
t = HTimer()
Test4()
t = HTimer() - t
m = Timer() - m
PrintResult("Test 4 time: ")
//-------------------------
//-------------------------
Sync
Nice Wait 1000
Loop
End
//==================================================
Function PrintResult(msg$)
a$(n) = msg$ + Str$(t) + " - " + Str$(t*0.001,3) + "|" + Str$(m) + " ms "
Inc n: a$(n) = "Done in " + Str$((t*0.001)*0.001,3) + " seconds"
av# = ((t * 0.001) * 0.001 )
t# = ( Max( av#, 0.000001) )
c# = 1.0 / t#
Inc n: a$(n) = Str$(t#,3) + " seconds per step"
Inc n: a$(n) = Str$(c#,1) + " steps per second"
st = n - 3
en = n
For e = st to en
Print a$(e)
Next e
Print "---------------------------------"
Inc n
Endfunction
//==================================================
Function Test1()
For i = 1 to 5000
Next i
Endfunction
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function Test2()
For i = 1 to 5000
Next i
Endfunction
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function Test3()
For i = 1 to 5000
Next i
Endfunction
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function Test4()
For i = 1 to 5000
Next i
Endfunction
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function HTimer()
Local ti as Double Integer
ti = HiTimer(1000000)
Endfunction ti