]> gitweb.factorcode.org Git - factor.git/blob - extra/project-euler/ave-time/ave-time.factor
Merge commit 'chris/master'
[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 combinators 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 : ave-benchmarks ( seq -- pair )
10     flip [ mean round ] map ;
11
12 PRIVATE>
13
14 : collect-benchmarks ( quot n -- seq )
15   [
16     >r >r datastack r> [ benchmark 2array , ] curry tuck
17     [ with-datastack drop ] 2curry r> swap times call
18   ] { } make ;
19
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