]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/project-euler/ave-time/ave-time.factor
Merge git://projects.elasticdog.com/git/factor into public
[factor.git] / extra / project-euler / ave-time / ave-time.factor
index 56f7185095b604beaa30a9572b2cfbd7691478fb..be39b26a97ea5f68857dfd710880b98442896fd5 100644 (file)
@@ -1,7 +1,7 @@
-! Copyright (c) 2007 Aaron Schaefer
+! 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 continuations ;
+USING: continuations 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