REBOL 3.0

Changes to high resolution time in R3

Carl Sassenrath, CTO
REBOL Technologies
10-Nov-2009 18:35 GMT

Article #0293
Main page || Index || Prior Article [0292] || Next Article [0294] || 1 Comments || Send feedback

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.

Notes:

  1. Keep in mind that your system is multitasking, so you will see variations in timing based on time used by other applications.
  2. 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.
  3. 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.
  4. 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.

Examples:

Script that accurately shows total boot time:

REBOL [file: %boot-time.r]
print stats/timer

Result when script is run:

Evaluating: /C/rebol/boot-time.r
0:00:00.023805

Simple example timing the SINE function:

delta-time [loop 100 [sine 123]]
0:00:00.000089

This line was evaluated several times to observe that the result was relatively accurate.

1 Comments

REBOL 3.0
Updated 6-Oct-2024 - Edit - Copyright REBOL Technologies - REBOL.net