Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

# Timer

Returns the number of seconds that have elapsed since midnight UTC.

## Synopsis

```Timer
```

none

### Description

Timer is commonly used to determine elapsed time. However, because Timer resets to zero at midnight UTC, a robust timer program cannot simply subtract the start time from the end time.

Timer returns the elapsed number of seconds since midnight in Coordinated Universal Time (UTC), which is independent of time zone. Consequently, Timer provides a time value that is uniform across time zones. This may differ from the local time value. The Timer returned value is a decimal numeric value that counts the time in seconds and fractions thereof. The number of digits in the fractional seconds may vary from zero to nine, depending on the precision of your computer’s time-of-day clock. On Windows systems the fractional precision is three decimal digits; on UNIX® systems it is six decimal digits. Timer suppresses leading and trailing zeroes. If the fractional portion is exactly zero, the trailing decimal point is also suppressed.

## Example

The following example compares two Timer function values to determine the time it takes to iterate a For...Next loop 50 times. In this example, each iteration through the loop prints out the ASCII character set. (For the purpose of demonstration, a Sleep statement is included so that the elapsed time is not smaller than the available fractional precision.) The before and after timer values are compared, and the elapsed time displayed. The Else clause is provided to handle the midnight reset situation.

```Dim StartTime,EndTime,TimeIt
StartTime = Timer
For I = 1 To 50
Sleep .05
x = 32
Print I
For N = 1 To 94
Print Chr(x)
x = x + 1
Next
Println ""
Next
EndTime = Timer
Println "start time: ",StartTime
Println "end time: ",EndTime
If EndTime >= StartTime Then
TimeIt = EndTime - StartTime
Else
EndTime = EndTime + 86400
TimeIt = EndTime - StartTime
End If
Println "elapse time: ",TimeIt
```