1 ! Copyright (c) 2007, 2008 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
7 : nth-place ( x n -- y )
8 10 swap ^ [ * round >integer ] keep /f ;
10 : collect-benchmarks ( quot n -- seq )
14 '[ _ gc benchmark 1000 / , ] tuck
15 '[ _ _ with-datastack drop ]
17 [ 1- ] tri* swap times call
20 : ave-time ( quot n -- )
21 [ collect-benchmarks ] keep swap
22 [ std 2 nth-place ] [ mean round >integer ] bi [
23 # " ms ave run time - " % # " SD (" % # " trials)" %
24 ] "" make print flush ; inline