Paste: faster?

Author: randy7
Mode: factor
Date: Fri, 23 Jan 2009 19:09:48
Plain Text |
IN: little-test
USING: continuations kernel math sequences system ;

: isolated-time ( quote -- delta-in-millis )
    { } swap '[ millis @ millis ] with-datastack 
    [ first ] [ peek ] bi swap - ; 

: faster? ( quot1 quot2 -- ? )
    [ isolated-time ] bi@ < ;
    
! [ 2 3 + ] [ 3 4 - 1 seconds sleep ] faster?   
! ==> t

Annotation: addition

Author: randy7
Mode: factor
Date: Fri, 23 Jan 2009 20:01:55
Plain Text |
! could surely use a cleanup



:: bench-ave-time ( n quot -- avg ) ! (if n > 100,000, use 'drop' to drop the value at the end of your quot. )
    SYMBOL: accum-vector 
    V{ } clone accum-vector set
12 [
 [ n quot times ] isolated-time 
accum-vector get swap suffix accum-vector set 
   ] times
accum-vector get 

natural-sort 1 tail 1 head*  mean 

n pprint " operations took: " write >float pprint " milliseconds." write nl
;

! 300000 [ 3 4 * drop ] bench-ave-time
! 300000 operations took: 31.2 milliseconds.

Annotation: some more

Author: randy7
Mode: factor
Date: Fri, 23 Jan 2009 20:25:24
Plain Text |
IN: little-test
USING: fry locals continuations kernel math sequences system math.statistics ;

: isolated-time ( quote -- delta-in-millis )
    { } swap '[ millis @ millis ] with-datastack 
    [ first ] [ peek ] bi swap - ; 

: faster? ( quot1 quot2 -- ? )
    [ isolated-time ] bi@ < ;
    
! [ 2 3 + ] [ 3 4 - 1 seconds sleep ] faster?   
! ==> t


:: bench-ave-time ( n quot -- avg ) ! (if n > 100,000, use 'drop' to drop the value at the end of your quot. )
    SYMBOL: accum-vector 
    V{ } clone accum-vector set
12 [
 [ n quot times ] isolated-time 
accum-vector get swap suffix accum-vector set 
   ] times
accum-vector get 

natural-sort 1 tail 1 head*  mean ;

: bench-timed. ( n quot -- )
    [ bench-ave-time ] 
    [ drop pprint " operations took: " write >float pprint " milliseconds." write nl ] 2bi ; 
    
    

! 300000 [ 3 4 * drop ] bench-ave-time.
! 300000 operations took: 31.2 milliseconds.


: bfaster? ( n quot1 quot2 -- ? )
    pick swap [ bench-ave-time ] 2bi@ < ;

New Annotation

Summary:
Author:
Mode:
Body: