2008-07-20 21:52:39 -04:00
|
|
|
! Copyright (c) 2007 Aaron Schaefer.
|
2007-12-18 20:57:16 -05:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-09-08 02:20:42 -04:00
|
|
|
USING: continuations io kernel math math.functions math.parser math.statistics
|
2008-09-10 23:11:40 -04:00
|
|
|
namespaces make tools.time ;
|
2007-12-18 20:57:16 -05:00
|
|
|
IN: project-euler.ave-time
|
|
|
|
|
|
|
|
|
|
: collect-benchmarks ( quot n -- seq )
|
2007-12-28 08:17:31 -05:00
|
|
|
[
|
2008-05-07 18:42:41 -04:00
|
|
|
>r >r datastack r> [ benchmark , ] curry tuck
|
2007-12-28 08:17:31 -05:00
|
|
|
[ with-datastack drop ] 2curry r> swap times call
|
|
|
|
|
] { } make ;
|
2007-12-18 20:57:16 -05:00
|
|
|
|
2008-07-27 17:46:43 -04:00
|
|
|
: nth-place ( x n -- y )
|
|
|
|
|
10 swap ^ [ * round ] keep / ;
|
|
|
|
|
|
2007-12-18 20:57:16 -05:00
|
|
|
: ave-time ( quot n -- )
|
2008-07-27 17:46:43 -04:00
|
|
|
[ collect-benchmarks ] keep
|
|
|
|
|
swap [ std 2 nth-place ] [ mean round ] bi [
|
|
|
|
|
# " ms ave run time - " % # " SD (" % # " trials)" %
|
2007-12-18 20:57:16 -05:00
|
|
|
] "" make print flush ; inline
|