]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/project-euler/ave-time/ave-time.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / extra / project-euler / ave-time / ave-time.factor
index 56f7185095b604beaa30a9572b2cfbd7691478fb..dc521d4d70f0bd2520877b2f3c684439ace125f0 100644 (file)
@@ -1,16 +1,24 @@
-! Copyright (c) 2007 Aaron Schaefer
+! Copyright (c) 2007, 2008 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 fry io kernel make math math.functions
+math.parser math.statistics memory tools.time ;
 IN: project-euler.ave-time
 
+: nth-place ( x n -- y )
+    10^ [ * round >integer ] keep /f ;
+
 : collect-benchmarks ( quot n -- seq )
-  [
-    >r >r datastack r> [ benchmark , ] curry tuck
-    [ with-datastack drop ] 2curry r> swap times call
-  ] { } make ;
+    [
+        [ datastack ]
+        [
+            '[ _ gc benchmark 1000 / , ] tuck
+            '[ _ _ with-datastack drop ]
+        ]
+        [ 1 - ] tri* swap times call
+    ] { } make ; inline
 
 : ave-time ( quot n -- )
-    [ collect-benchmarks ] keep swap mean round [
-        # " ms run time - " % # " trials" %
+    [ collect-benchmarks ] keep swap
+    [ std 2 nth-place ] [ mean round >integer ] bi [
+        # " ms ave run time - " % # " SD (" % # " trials)" %
     ] "" make print flush ; inline