]> gitweb.factorcode.org Git - factor.git/blob - extra/project-euler/ave-time/ave-time.factor
Merge git://projects.elasticdog.com/git/factor into public
[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: continuations io kernel math math.functions math.parser math.statistics
4     namespaces tools.time ;
5 IN: project-euler.ave-time
6
7 : collect-benchmarks ( quot n -- seq )
8   [
9     >r >r datastack r> [ benchmark , ] curry tuck
10     [ with-datastack drop ] 2curry r> swap times call
11   ] { } make ;
12
13 : nth-place ( x n -- y )
14     10 swap ^ [ * round ] keep / ;
15
16 : ave-time ( quot n -- )
17     [ collect-benchmarks ] keep
18     swap [ std 2 nth-place ] [ mean round ] bi [
19         # " ms ave run time - " % # " SD (" % # " trials)" %
20     ] "" make print flush ; inline