]> gitweb.factorcode.org Git - factor.git/commitdiff
Rewrite of collect-benchmarks in ave-time vocab
authorAaron Schaefer <aaron@elasticdog.com>
Tue, 4 Nov 2008 03:56:32 +0000 (22:56 -0500)
committerAaron Schaefer <aaron@elasticdog.com>
Tue, 4 Nov 2008 03:56:32 +0000 (22:56 -0500)
extra/project-euler/ave-time/ave-time.factor

index df96d5e21105cede7807d470d2eb6bfbc097cb16..2a516513a56e703a5bdf3df1dbcaf6a73c7065eb 100644 (file)
@@ -1,20 +1,21 @@
 ! Copyright (c) 2007 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: continuations io kernel math math.functions math.parser math.statistics
-    namespaces make tools.time ;
+USING: continuations fry io kernel make math math.functions math.parser
+    math.statistics memory 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 ;
+    [
+        [ datastack ]
+        [ '[ _ gc benchmark , ] tuck '[ _ _ with-datastack drop ] ]
+        [ 1- ] tri* swap times call
+    ] { } make ;
 
 : nth-place ( x n -- y )
     10 swap ^ [ * round ] keep / ;
 
 : ave-time ( quot n -- )
-    [ collect-benchmarks ] keep
-    swap [ std 2 nth-place ] [ mean round ] bi [
+    [ collect-benchmarks ] keep swap
+    [ std 2 nth-place ] [ mean round ] bi [
         # " ms ave run time - " % # " SD (" % # " trials)" %
     ] "" make print flush ; inline