Precision delta time measurements
The delta-time function (or dt for short) is useful for timing your code. But, if you source it:
>> source delta-time
delta-time: make function! [[
{Delta-time - return the time it takes to evaluate a block.}
block [block!]
/local start
][
start: now/precise
do block
difference now/precise start
]]
you'll see that it uses now/precise.
A more accurate measurement would be to use stats/timer, which gives microsecond resolution.
The new function becomes:
delta-time: funct [
{Delta-time - return the time it takes to evaluate a block.}
block [block!]
][
start: stats/timer
do block
to-time stats/timer - start / 1.0e6
]
Examples:
>> delta-time [loop 1000 [next "test"]]
== 0:00:00.000464
>> delta-time [wait 1]
== 0:00:01.001079
In A95, this change will be made, unless you know some reason not to.
See also the article: New Timebase.
19 Comments
|