View script | License | Download documentation as: HTML or editable | Download script | History |
[0.052] 17.576k
Documentation for: timeblk.rUsage document for %timeblk.r1. Introduction to %timeblk.rThis script is a handy tool that times REBOL code. This usage document also highlights other timing related scripts, and some of this information is shared among the documentation. 2. timeblk At a GlanceScript: "Time a Block" (28-Oct-1998) == [ fib: func [x] [ if (x < 2) [return x] return (fib x - 2) + (fib x - 1) ] time-block [fib 20] ... >> do http://www.rebol.org/cgi-bin/cgiwrap/rebol/download-a-script.r?script-name=timeblk.r connecting to: www.rebol.org >> do example 0:00:01 0:00:01A little bit out of order, so the floating table of contents doesn't hide part of the url!. 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 %timeblk.rThere are a few change that can be made to this script. The script in the repository, is a sample. You need to call time-block with your own block of code. 5.1. Running %timeblk.rThis utility is simple to use. Just DO it. >> do %timeblk.r This defines the time-block function, and defines an example. To be more useful, the example should be commented out to remove example from the global namespace. The time-block function executes a DO on the code in the passed in block!, and displays the elapsed time. 5.1.1. Refinementstime-block also accepts a /reps refinement that takes an integer! argument, for the number of repetitions. This allows for more accurate timings in some circumstances, be careful with side-effects in the block of code you are timing. 5.1.2. Another timing toolkitFor comprehensive named events with 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=timeblk.rbut that won't give you information on your own code timings. 6. What you can learnThe example block defines a nice little Fibonacci Sequence recursive function. REBOL does many things, and recursion is one of them. 6.1. Hidden gems everywhereThis also highlights one of the aspect of the scripts in the repository. Many of the samples include gems of code snippets worthy of exploration, perhaps unrelated to the script's main purpose. The example block defines a fib function, and calls the main time-block function from within inside this block. There are quite a few ways of encapsulating code and data with REBOL. As you learn more, and write programs that are destined for sharing, these encapsulation techniques become more important. Shared code should add a minimum of words to the global namespace. 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 breakDon't try and execute the sample fib function with large values. By nature, recursion can spin a stack frame out of control quite quickly. A midnight rollover will give wonky results. With a fast processor, you may get a lot of 0:00 second results. 8. Credits
|