RosettaCodeData/Task/Rate-counter/Liberty-BASIC/rate-counter.basic

57 lines
1.3 KiB
Plaintext

Print "Rate counter"
print "Precision: system clock, ms ";
t0=time$("ms")
while time$("ms")=t0 'busy loop till click ticks
wend
print time$("ms")-t0
print
Print "Run jobs N times, report every time"
Print "After that, report average time"
N=10
t00=time$("ms")
for i = 1 to 10
scan
t0=time$("ms")
'any code we want to measure goes here
res = testFunc()
'end of measured code
t1=time$("ms")
ElapsedTime = t1-t0
print "Job #";i;" Elapsed time, ms ";ElapsedTime, 1000/ElapsedTime; " ticks per second"
next
print "---------------------------------"
print "Average time, ms, is ";(t1-t00)/N, 1000/((t1-t00)/N); " ticks per second"
print
print "Run jobs for not less then N seconds (if time up, it'll finish last job)"
print "After that, report average time"
NSec=5
i = 0
t00=time$("ms")
while time$("ms")<t00+NSec*1000
scan
i = i+1
t0=time$("ms")
'any code we want to measure goes here
res = testFunc()
'end of measured code
t1=time$("ms")
ElapsedTime = t1-t0
print "Job #";i;" Elapsed time, ms ";ElapsedTime, 1000/ElapsedTime; " ticks per second"
wend
print "---------------------------------"
print "Average time, ms, is ";(t1-t00)/i, 1000/((t1-t00)/i); " ticks per second"
end
function testFunc()
s=0
for i = 1 to 30000
s=s+sin(i)/30000
next
testFunc = s
end function