Tech Tip: Measuring Execution Time of Code
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: September 15, 2025
4D has various commands that return time related values such as, Current Time and Timestamp.
To measure the execution time of some code, the typical recomendation is to use either the Milliseconds command or the Tickcount command. Both commands behave the same returning the amount of time that has passed since the machine executing the command was started. The only difference is in their precision.
The Milliseconds command returns the number of milliseconds since the machine was started which is 1/1000 of a second. The Tickcount command returns the number of ticks since the machine was started which is 1/60 of a second. Depending on what is being measured, one might be more applicable than the other.
Since the commands return the amount of time that has passed since the machine has started, to measure the time code takes to execute, just measure the time passed before and after the execution of the command and get the difference. This will be the amount of time (in Ticks) it took the code to execute:
If a higher precision was needed, the Tickcount command can be replaced with the Milliseconds command.
To measure the execution time of some code, the typical recomendation is to use either the Milliseconds command or the Tickcount command. Both commands behave the same returning the amount of time that has passed since the machine executing the command was started. The only difference is in their precision.
The Milliseconds command returns the number of milliseconds since the machine was started which is 1/1000 of a second. The Tickcount command returns the number of ticks since the machine was started which is 1/60 of a second. Depending on what is being measured, one might be more applicable than the other.
Since the commands return the amount of time that has passed since the machine has started, to measure the time code takes to execute, just measure the time passed before and after the execution of the command and get the difference. This will be the amount of time (in Ticks) it took the code to execute:
var $startTime; $endTime; $executionTime : Integer $startTime:=Tickcount // Some code // ... // ... $endTime:=Tickcount $executionTime:=$endTime-$startTime |
If a higher precision was needed, the Tickcount command can be replaced with the Milliseconds command.