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.




' FB 1.05.0 Win64
 
Function sumToLimit(limit As UInteger) As UInteger
  Dim sum As UInteger = 0
  For i As UInteger = 1 To limit
    sum += i
  Next
  Return sum
End Function
 
Dim As Double start = timer
Dim limit As UInteger = 100000000
Dim result As UInteger = sumToLimit(limit)
Dim ms As UInteger = Int(1000 * (timer - start) + 0.5)
Print "sumToLimit("; Str(limit); ") = "; result
Print "took ";  ms; " milliseconds to calculate"
Print
Print "Press any key to quit"
Sleep