1 USING: arrays help.markup help.syntax math memory quotations sequences system tools.time ;
2 IN: project-euler.ave-time
4 HELP: collect-benchmarks
5 { $values { "quot" quotation } { "n" integer } { "seq" sequence } }
6 { $description "Runs a quotation " { $snippet "n" } " times, collecting the wall clock time and the time spent in the garbage collector into pairs inside of a sequence." }
7 { $notes "The stack effect of " { $snippet "quot" } " is inferred and only one set of outputs will remain on the stack no matter how many trials are run."
9 "A nicer word for interactive use is " { $link ave-time } "." } ;
12 { $values { "quot" quotation } { "n" integer } }
13 { $description "Runs a quotation " { $snippet "n" } " times, then prints the average run time and the average time spent in the garbage collector." }
14 { $notes "The stack effect of " { $snippet "quot" } " is inferred and only one set of outputs will remain on the stack no matter how many trials are run." }
16 "This word can be used to compare performance of the non-optimizing and optimizing compilers."
18 "First, we time a quotation directly; quotations are compiled by the non-optimizing quotation compiler:"
19 { $unchecked-example "[ 1000000 0 [ + ] reduce drop ] 10 ave-time" "1116 ms run / 6 ms GC ave time - 10 trials" }
20 "Now we define a word and compile it with the optimizing word compiler. This results is faster execution:"
21 { $unchecked-example ": foo 1000000 0 [ + ] reduce ;" "\\ foo compile" "[ foo drop ] 10 ave-time" "202 ms run / 13 ms GC ave time - 10 trials" }
24 { benchmark collect-benchmarks gc-time millis time ave-time } related-words