]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/project-euler/ave-time/ave-time.factor
factor: trim using lists
[factor.git] / extra / project-euler / ave-time / ave-time.factor
index c8212b400946fc5408ed190a0115fb75d50efe4c..340c85d2af5158f7e565bcc17c166f41669ec39b 100644 (file)
@@ -1,16 +1,16 @@
-! 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 ;
+USING: combinators.smart formatting io kernel math math.functions
+math.statistics memory sequences tools.time ;
 IN: project-euler.ave-time
 
-: collect-benchmarks ( quot n -- seq )
-  [
-    >r >r datastack r> [ benchmark , ] curry tuck
-    [ with-datastack drop ] 2curry r> swap times call
-  ] { } make ;
+MACRO: collect-benchmarks ( quot n -- seq )
+    swap '[ _ [ [ [ _ nullary ] preserving ] gc benchmark 6 10^ / ] replicate ] ;
 
 : ave-time ( quot n -- )
-    [ collect-benchmarks ] keep swap mean round [
-        # " ms run time - " % # " trials" %
-    ] "" make print flush ; inline
+    [
+        collect-benchmarks
+        [ mean round >integer ]
+        [ std ] bi
+    ] keep
+    "%d ms ave run time - %.2f SD (%d trials)\n" printf flush ; inline