Paste: ave-time vocab

Author: elasticdog
Mode: factor
Date: Tue, 4 Nov 2008 03:28:57
Plain Text |
USING: continuations fry io kernel make math math.functions math.parser
    math.statistics memory tools.time ;
IN: project-euler.ave-time

: collect-benchmarks ( quot n -- seq )
    [
        [ datastack ]
        [ '[ _ gc benchmark , ] tuck '[ _ _ with-datastack drop ] ]
        [ 1- ] tri* swap times call
    ] { } make ;

: nth-place ( x n -- y )
    10 swap ^ [ * round ] keep / ;

: ave-time ( quot n -- )
    [ collect-benchmarks ] keep swap
    [ std 2 nth-place ] [ mean round ] bi [
        # " ms ave run time - " % # " SD (" % # " trials)" %
    ] "" make print flush ; inline

New Annotation

Summary:
Author:
Mode:
Body: