2008-11-24 22:05:43 -05:00
|
|
|
! Copyright (c) 2007, 2008 Aaron Schaefer.
|
2007-12-18 20:57:16 -05:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-11-03 22:56:32 -05:00
|
|
|
USING: continuations fry io kernel make math math.functions math.parser
|
|
|
|
math.statistics memory tools.time ;
|
2007-12-18 20:57:16 -05:00
|
|
|
IN: project-euler.ave-time
|
|
|
|
|
2008-11-24 22:05:43 -05:00
|
|
|
: nth-place ( x n -- y )
|
|
|
|
10 swap ^ [ * round >integer ] keep /f ;
|
|
|
|
|
2007-12-18 20:57:16 -05:00
|
|
|
: collect-benchmarks ( quot n -- seq )
|
2008-11-03 22:56:32 -05:00
|
|
|
[
|
|
|
|
[ datastack ]
|
2008-11-24 22:05:43 -05:00
|
|
|
[
|
|
|
|
'[ _ gc benchmark 1000 / , ] tuck
|
|
|
|
'[ _ _ with-datastack drop ]
|
|
|
|
]
|
2008-11-03 22:56:32 -05:00
|
|
|
[ 1- ] tri* swap times call
|
2008-11-05 19:24:19 -05:00
|
|
|
] { } make ; inline
|
2007-12-18 20:57:16 -05:00
|
|
|
|
|
|
|
: ave-time ( quot n -- )
|
2008-11-03 22:56:32 -05:00
|
|
|
[ collect-benchmarks ] keep swap
|
2008-11-24 22:05:43 -05:00
|
|
|
[ std 2 nth-place ] [ mean round >integer ] bi [
|
2008-07-27 17:46:43 -04:00
|
|
|
# " ms ave run time - " % # " SD (" % # " trials)" %
|
2007-12-18 20:57:16 -05:00
|
|
|
] "" make print flush ; inline
|