Function MicroSeconds() Foundation
Determines the number of microseconds that have elapsed since the last machine startup.
MicroSeconds() --> nMicroSeconds
The function MicroSeconds() returns a numeric integer value in the range of 0 to 86,399,999,999. It corresponds to the system time, in the form of the number of microseconds that have elapsed since the last machine startup.
The environment function MicroSeconds() provides the current system time in microseconds (one millionth of a second). The function can be used for code profiling, where the system time is determined at the beginning and the end of a procedure and the elapsed time is calculated.
// In this example, the time to run two different pieces of code that
// both create an array filled with random characters is compared using
// MicroSeconds(). This is a rudimentary form of profiling.
// The first approach uses AAdd() to populate an empty array in a loop,
// while the second approach creates a pre-dimensioned array using the
// Array() function and then updates each existing array item.
#define ARRAY_ITEMS 50000
PROCEDURE Main()
LOCAL aArray
LOCAL nItem
LOCAL nMicroSecs1
LOCAL nMicroSecs2
LOCAL nMicroSecs3
nMicroSecs1 := MicroSeconds()
aArray := {}
FOR nItem := 1 TO ARRAY_ITEMS
AAdd(aArray, Chr(RandomInt(65, 90)))
NEXT
nMicroSecs2 := MicroSeconds()
aArray := Array(ARRAY_ITEMS)
FOR nItem := 1 TO ARRAY_ITEMS
aArray[nItem] := Chr(RandomInt(65, 90))
NEXT
nMicroSecs3 := MicroSeconds()
CLS
? "Time for AAdd() :", nMicroSecs2 - nMicroSecs1
? "Time for Array():", nMicroSecs3 - nMicroSecs2
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.