]> gitweb.factorcode.org Git - factor.git/blob - extra/project-euler/ave-time/ave-time.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / extra / project-euler / ave-time / ave-time.factor
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
4 math.parser math.statistics memory tools.time ;
5 IN: project-euler.ave-time
6
7 : nth-place ( x n -- y )
8     10^ [ * round >integer ] keep /f ;
9
10 : collect-benchmarks ( quot n -- seq )
11     [
12         [ datastack ]
13         [
14             '[ _ gc benchmark 1000 / , ] tuck
15             '[ _ _ with-datastack drop ]
16         ]
17         [ 1 - ] tri* swap times call
18     ] { } make ; inline
19
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