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