Documention for: timeit.r Created by: btiffin on: 7-May-2007 Last updated by: btiffin on: 8-May-2007 Format: text/editable Downloaded on: 30-Apr-2025 [h1 Usage document for %timeit.r [contents [numbering-on [h2 Introduction to %timeit.r [p This script is a handy tool that times REBOL code. [p This document also highlights other timing related scripts, and some of this information is shared among the documentation. [h2 timeit At a Glance [asis/style/font-size:75% >> 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 asis] [h2 Timing related scripts [table/att/border="1px"/style/font-size:75% [row [cell [link http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=timeit.r "%timeit.r" [cell A simple timing function [row [cell [link http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=timeblk.r "%timeblk.r" [cell Very similar to %timeit.r [row [cell [link http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=timepage.r "%timepage.r" [cell Times how long it takes to read a web page [row [cell [link http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=timesites.r "%timesites.r" [cell Times how long each read of a block of web pages takes [row [cell [link http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=timewebs.r "%timewebs.r" [cell Similar to %timesites.r, but keeps timings in a block [row [cell [link http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=profiler.r "%profiler.r" [cell Sophisticated timing of REBOL code sections [row [cell [link http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=profile-timer.r "%profile-timer.r" [cell Sophisticated timing of REBOL code sections, with named events. [row [cell [link http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=timer-style.r "%timer-style.r" [cell A graphical timer, with example start, stop, reset and save. [row [cell [link http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=remind.r "%remind.r" [cell An example of setting a reminder timer, that can email the reminder [row [cell [link http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=now.r "%now.r" [cell A simple script to find out your age in seconds. [row [cell [link http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=set-prompt.r "%set-prompt.r" [cell An example of setting the console prompt. Sets prompt to show current time and current directory. [row [cell [link http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=form-date.r "%form-date.r" [cell Not really a timer, but can format timing output ala strftime table] [h2 Another excellent timing script, not in the library, [link http://www.fm.vslib.cz/~ladislav/rebol/timblk.r "Ladislav's precise timing" is a very precise timing script, includes time-block, and time-tick. Returns the system clock tick-time on execution. [h2 Using %timeit.r [p 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. [h3 Running %timeit.r [p This utility is simple to use. Just <strong>DO</strong> it. [asis >> do %timeit.r asis] [p 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**. [p 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 [br [link http://www.rebol.org/cgi-bin/cgiwrap/rebol/view-script.r?script=profile-timer.r "%profile-timer.r" and [link http://www.rebol.org/cgi-bin/cgiwrap/rebol/documentation.r?script=profile-timer.r "%profile-timer.r documentation" [h3 Direct execution from the library [p This script can be executed directly from the library [asis/style/font-size:75% >> do http://www.rebol.org/cgi-bin/cgiwrap/rebol/download-a-script.r?script-name=timeit.r asis] but that won't give you information on your own code timings, but will define the **timeit** function. [h2 What you can learn [p The use of **use** for local binding of variables to a block. [p 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. [p 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. [h2 What can break [p 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. [h2 Credits [table/att/border="1px" [row [cell %timeit.r [cell Original author: Unknown table] [list [li The rebol.org Library Team [li Usage document by Brian Tiffin, Library Team Apprentice, [date list]