Skip to content

getTimer

MicroBlaster edited this page Jul 9, 2020 · 4 revisions

Purpose: Retrieves the Time Stamp Counter (RDTSC), which is the number of CPU ticks since power on.

Syntax: getTimer var

var: A variable to hold the tick count.

Notes: Use StartTimer and StopTimer as an easier way to get performance measurements in MilliSeconds.

The result of this command is a 64-bit Integer. To measure the duration of an event in seconds, you will need to know the CPU speed in Hz. To simply compare routines to see which is faster, there is no reason to do the conversion to seconds. Merely get the duration for the first routine, then for the second routine, and whichever has the smaller number of Ticks for the interval is the faster routine.

Example:

getTimer $startTicks
# Perform some routine here
getTimer $stopTicks
setVar $durationTicks ($stopTicks - $startTicks)

# Now divide by CPU Hz if you need to convert Ticks to seconds. (2.2 GHz here)
# You will need to set the precision according to your desired accuracy, before dividing.
setPrecision 18
setVar $seconds ($durationTicks / 2200000000)
setPrecision 0
echo "*Time lapse in Seconds: " $seconds "*"

Clone this wiki locally