Task

Write a program which uses a timer (with the least granularity available
on your system) to time how long a function takes to execute.

Whenever possible, use methods which measure only the processing time used
by the current process; instead of the difference in system time
between start and finish, which could include time used by
other processes on the computer.

This task is intended as a subtask for Measure relative performance of sorting algorithms implementations.




BYTE RTCLOK1=$13
BYTE RTCLOK2=$14
BYTE PALNTSC=$D014
 
PROC Count(CARD max)
  CARD i
 
  FOR i=1 TO max DO OD
RETURN
 
CARD FUNC GetFrame()
  CARD res
  BYTE lsb=res,msb=res+1
 
  lsb=RTCLOK2
  msb=RTCLOK1
RETURN (res)
 
CARD FUNC FramesToMs(CARD frames)
  CARD res
 
  IF PALNTSC=15 THEN
    res=frames*60
  ELSE
    res=frames*50
  FI
RETURN (res)
 
PROC Main()
  CARD ARRAY c=[1000 2000 5000 10000 20000 50000]
  CARD beg,end,diff,diffMs
  BYTE i
 
  FOR i=0 TO 5
  DO
    PrintF("Count to %U takes ",c(i))
    beg=GetFrame()
    Count(c(i))
    end=GetFrame()
    diff=end-beg
    diffMs=FramesToMs(diff)
    PrintF("%U ms%E",diffMs)
  OD
RETURN