]> gitweb.factorcode.org Git - factor.git/blob - extra/project-euler/ave-time/ave-time.factor
Fix conflict
[factor.git] / extra / project-euler / ave-time / ave-time.factor
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
6
7 <PRIVATE
8
9 : clean-stack ( quot -- )
10     infer dup effect-out swap effect-in - [ drop ] times ;
11
12 : ave-benchmarks ( seq -- pair )
13     flip [ mean round ] map ;
14
15 PRIVATE>
16
17 : collect-benchmarks ( quot n -- seq )
18     [
19         1- [ [ benchmark ] keep -rot 2array , [ clean-stack ] keep ] times
20     ] curry { } make >r benchmark 2array r> swap add ; inline
21
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