1 ! Copyright (c) 2007 Aaron Schaefer
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays effects inference io kernel math math.functions math.parser
4 math.statistics namespaces sequences tools.time ;
5 IN: project-euler.ave-time
9 : clean-stack ( quot -- )
10 infer dup effect-out swap effect-in - [ drop ] times ;
12 : ave-benchmarks ( seq -- pair )
13 flip [ mean round ] map ;
17 : collect-benchmarks ( quot n -- seq )
19 1- [ [ benchmark ] keep -rot 2array , [ clean-stack ] keep ] times
20 ] curry { } make >r benchmark 2array r> swap add ; inline
22 : ave-time ( quot n -- )
23 [ collect-benchmarks ] keep swap ave-benchmarks [
24 dup second # " ms run / " % first # " ms GC ave time - " % # " trials" %
25 ] "" make print flush ; inline