Script Library: 1219 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Documentation for: timeit.r


Usage document for %timeit.r

1. Introduction to %timeit.r

This script is a handy tool that times REBOL code.

This document also highlights other timing related scripts, and some of this information is shared among the documentation.

2. timeit At a Glance

 >> do http://www.rebol.org/cgi-bin/cgiwrap/rebol/download-a-script.r?script-name=timeit.r
 connecting to: www.rebol.org
 Script: "Time-It Function" (3-Jun-1999)
 0:00
 0:00:03
 connecting to: www.rebol.com
 0:00:05
 

3. Timing related scripts

%timeit.r  A simple timing function
%timeblk.r  Very similar to %timeit.r
%timepage.r  Times how long it takes to read a web page
%timesites.r  Times how long each read of a block of web pages takes
%timewebs.r  Similar to %timesites.r, but keeps timings in a block
%profiler.r  Sophisticated timing of REBOL code sections
%profile-timer.r  Sophisticated timing of REBOL code sections, with named events.
%timer-style.r  A graphical timer, with example start, stop, reset and save.
%remind.r  An example of setting a reminder timer, that can email the reminder
%now.r  A simple script to find out your age in seconds.
%set-prompt.r  An example of setting the console prompt. Sets prompt to show current time and current directory.
%form-date.r  Not really a timer, but can format timing output ala strftime

4. Another excellent timing script, not in the library,

Ladislav's precise timing  is a very precise timing script, includes time-block, and time-tick. Returns the system clock tick-time on execution.

5. Using %timeit.r

There are a few change that can be made to this script. The script in the repository, is a sample. You need to wrap timeit calls around your own code.

5.1. Running %timeit.r

This utility is simple to use. Just DO it.

 >> do %timeit.r
 

This defines the timeit function, and executes the example. To be more useful, the example should be commented out. Simple enough, either remove the example block and the do example line or place a ; in front of the do example. Note the second method adds more litter to the global name space, as it defines (or redefines, a worse case scenario) a global example.

The timeit function does no output on first call, it acts as "start timer" . The next call will display the elapsed time. And further calls will display the next elapsed time. For comprehensive cumulative times, take a look at
%profile-timer.r  and %profile-timer.r documentation 

5.2. Direct execution from the library

This script can be executed directly from the library

 >> do http://www.rebol.org/cgi-bin/cgiwrap/rebol/download-a-script.r?script-name=timeit.r
 
but that won't give you information on your own code timings, but will define the timeit function.

6. What you can learn

The use of use for local binding of variables to a block.

The way REBOL passes values back though execution. In this case the bound variable last-time is set to none, then the function is defined, which is returned as the value of the timeit set-word. This type of programming may become more prevalent in REBOL as we aim for more shareable scripts.

The time refinement of the now native function, now/time has a resolution of 1 second. Most new machines can cut through a lot of REBOL code in 1 second. More comprehensive timing utilities will use now/time/precise, for much finer grained timings.

7. What can break

Not much to break here, but a midnight rollover will give wonky results. And with a fast processor, you may get a lot of 0:00 second results.

8. Credits

%timeit.r Original author: Unknown
  • The rebol.org Library Team
  • Usage document by Brian Tiffin, Library Team Apprentice, Last updated: 8-May-2007