1 ! Copyright (c) 2007 Aaron Schaefer
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays combinators io kernel math math.functions math.parser
4 math.statistics namespaces sequences tools.time ;
5 IN: project-euler.ave-time
9 : ave-benchmarks ( seq -- pair )
10 flip [ mean round ] map ;
14 : collect-benchmarks ( quot n -- seq )
16 >r >r datastack r> [ benchmark 2array , ] curry tuck
17 [ with-datastack drop ] 2curry r> swap times call
20 : ave-time ( quot n -- )
21 [ collect-benchmarks ] keep swap ave-benchmarks [
22 dup second # " ms run / " % first # " ms GC ave time - " % # " trials" %
23 ] "" make print flush ; inline