Comments on: Changes to high resolution time in R3
I wanted to make this note so as not to be lost along the way. The A95 release (TBR this week) has some changes to high-resolution stats/timer timestamps:
- Changed from integer! to time! datatype (and delta-time has been updated for that change)
- Resolution is microseconds
- At boot time, prior to any initialization, it is set to 0:00:00.0 (see the note below to understand this value.)
- Computes delta with high-resolution timer ticks (on Win32) before frequency division. See warning note below.
- Keep in mind that your system is multitasking, so you will see variations in timing based on time used by other applications.
- To get more accurate timings for code-speed evaluation, you will need to use various timing techniques, such as those suggested by Ladislav, et.al. Simply timing one loop of a section of code is not accurate.
- Setting the base time to 0:00 on boot is an interesting feature. It lets you determine the time it takes for REBOL to initialize (quite a lot happens during boot.) Perhaps this value is debatable. An alternative might be to set it to the current time-of-day. However, by doing so, users might incorrectly assume that it would accurately indicate time-of-day, a false assumption.
- If your CPU changes speed (clock frequency) during the use of stats/timer, the result may not be accurate. That happens because we now compute the time delta based the full precision of the CPU counter and only divide the counter frequency after the delta is subtracted.
Script that accurately shows total boot time:
REBOL [file: %boot-time.r]
Result when script is run:
Simple example timing the SINE function:
delta-time [loop 100 [sine 123]]
This line was evaluated several times to observe that the result was relatively accurate.
Point 3 is cool as I've been wanting to read the uptime for a REBOL process for a while now. Boot time can be derived using NOW, so having it start at zero is fine.|
Post a Comment:
You can post a comment here. Keep it on-topic.