]> gitweb.factorcode.org Git - factor.git/commitdiff
Add standard deviation to output of ave-time benchmarking word
authorAaron Schaefer <aaron@elasticdog.com>
Sun, 27 Jul 2008 21:46:43 +0000 (17:46 -0400)
committerAaron Schaefer <aaron@elasticdog.com>
Sun, 27 Jul 2008 21:46:43 +0000 (17:46 -0400)
extra/project-euler/ave-time/ave-time-docs.factor
extra/project-euler/ave-time/ave-time.factor

index d8ee0846b05218e3d7abbe4a100c8d5e1e65670a..f2d6b89afcb1c215768cc7bdf3ca7e35aa4d3df0 100644 (file)
@@ -1,22 +1,31 @@
-USING: arrays help.markup help.syntax math memory quotations sequences system tools.time ;
+USING: arrays help.markup help.syntax math math.parser memory quotations
+    sequences system tools.time ;
 IN: project-euler.ave-time
 
 HELP: collect-benchmarks
 { $values { "quot" quotation } { "n" integer } { "seq" sequence } }
-{ $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." }
-{ $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."
+{ $description "Runs a quotation " { $snippet "n" } " times, collecting the wall clock time inside of a sequence." }
+{ $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."
     $nl
     "A nicer word for interactive use is " { $link ave-time } "." } ;
 
+HELP: nth-place
+{ $values { "x" float } { "n" integer } { "y" float } }
+{ $description "Rounds a floating point number to " { $snippet "n" } " decimal places." }
+{ $examples
+    "This word is useful for display purposes when showing 15 decimal places is not desired:"
+    { $unchecked-example "3.141592653589793 3 nth-place number>string" "\"3.142\"" }
+} ;
+
 HELP: ave-time
 { $values { "quot" quotation } { "n" integer } }
-{ $description "Runs a quotation " { $snippet "n" } " times, then prints the average run time and the average time spent in the garbage collector." }
-{ $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." }
+{ $description "Runs a quotation " { $snippet "n" } " times, then prints the average run time and standard deviation." }
+{ $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." }
 { $examples
     "This word can be used to compare performance of the non-optimizing and optimizing compilers."
     $nl
     "First, we time a quotation directly; quotations are compiled by the non-optimizing quotation compiler:"
-    { $unchecked-example "[ 1000000 0 [ + ] reduce drop ] 10 ave-time" "1116 ms run time - 10 trials" }
-    "Now we define a word and compile it with the optimizing word compiler. This results is faster execution:"
-    { $unchecked-example ": foo 1000000 0 [ + ] reduce ;" "\\ foo compile" "[ foo drop ] 10 ave-time" "202 ms run time - 10 trials" }
+    { $unchecked-example "[ 1000000 0 [ + ] reduce drop ] 10 ave-time" "465 ms ave run time - 13.37 SD (10 trials)" }
+    "Now we define a word and compile it with the optimizing word compiler. This results in faster execution:"
+    { $unchecked-example ": foo 1000000 0 [ + ] reduce ;" "\\ foo compile" "[ foo drop ] 10 ave-time" "202 ms ave run time - 22.73 SD (10 trials)" }
 } ;
index 081ee2e8bbd8a7d1eec283dcc1d7d5cf5cc3e5c5..ecf308ec11cd1a3a549e937793a74a7e62db3adc 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (c) 2007 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: arrays combinators io kernel math math.functions math.parser
-    math.statistics namespaces sequences tools.time ;
+USING: combinators io kernel math math.functions math.parser math.statistics
+    namespaces tools.time ;
 IN: project-euler.ave-time
 
 : collect-benchmarks ( quot n -- seq )
@@ -10,7 +10,11 @@ IN: project-euler.ave-time
     [ with-datastack drop ] 2curry r> swap times call
   ] { } make ;
 
+: nth-place ( x n -- y )
+    10 swap ^ [ * round ] keep / ;
+
 : ave-time ( quot n -- )
-    [ collect-benchmarks ] keep swap mean round [
-        # " ms run time - " % # " trials" %
+    [ collect-benchmarks ] keep
+    swap [ std 2 nth-place ] [ mean round ] bi [
+        # " ms ave run time - " % # " SD (" % # " trials)" %
     ] "" make print flush ; inline