View script | License | Download documentation as: HTML or editable | Download script | History |
[0.04] 16.491k
Documentation for: timeit.rUsage document for %timeit.r1. Introduction to %timeit.rThis 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
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.rThere 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.rThis 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 5.2. Direct execution from the libraryThis script can be executed directly from the library >> do http://www.rebol.org/cgi-bin/cgiwrap/rebol/download-a-script.r?script-name=timeit.rbut that won't give you information on your own code timings, but will define the timeit function. 6. What you can learnThe 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 breakNot 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
|