]> gitweb.factorcode.org Git - factor.git/blob - extra/project-euler/ave-time/ave-time-docs.factor
Merge git://projects.elasticdog.com/git/factor into public
[factor.git] / extra / project-euler / ave-time / ave-time-docs.factor
1 USING: arrays help.markup help.syntax math math.parser memory quotations
2     sequences system tools.time ;
3 IN: project-euler.ave-time
4
5 HELP: collect-benchmarks
6 { $values { "quot" quotation } { "n" integer } { "seq" sequence } }
7 { $description "Runs a quotation " { $snippet "n" } " times, collecting the wall clock time inside of a sequence." }
8 { $notes "The stack effect of " { $snippet "quot" } " is accounted for and only one set of outputs will remain on the stack no matter how many trials are run."
9     $nl
10     "A nicer word for interactive use is " { $link ave-time } "." } ;
11
12 HELP: nth-place
13 { $values { "x" float } { "n" integer } { "y" float } }
14 { $description "Rounds a floating point number to " { $snippet "n" } " decimal places." }
15 { $examples
16     "This word is useful for display purposes when showing 15 decimal places is not desired:"
17     { $unchecked-example "3.141592653589793 3 nth-place number>string" "\"3.142\"" }
18 } ;
19
20 HELP: ave-time
21 { $values { "quot" quotation } { "n" integer } }
22 { $description "Runs a quotation " { $snippet "n" } " times, then prints the average run time and standard deviation." }
23 { $notes "The stack effect of " { $snippet "quot" } " is accounted for and only one set of outputs will remain on the stack no matter how many trials are run." }
24 { $examples
25     "This word can be used to compare performance of the non-optimizing and optimizing compilers."
26     $nl
27     "First, we time a quotation directly; quotations are compiled by the non-optimizing quotation compiler:"
28     { $unchecked-example "[ 1000000 0 [ + ] reduce drop ] 10 ave-time" "465 ms ave run time - 13.37 SD (10 trials)" }
29     "Now we define a word and compile it with the optimizing word compiler. This results in faster execution:"
30     { $unchecked-example ": foo 1000000 0 [ + ] reduce ;" "\\ foo compile" "[ foo drop ] 10 ave-time" "202 ms ave run time - 22.73 SD (10 trials)" }
31 } ;