Paste: struct array benchmark -- factor version
Author: | slava |
Mode: | factor |
Date: | Fri, 28 Aug 2009 09:19:03 |
Plain Text |
USING: accessors classes.struct combinators.smart fry kernel
math math.functions math.order math.parser sequences
struct-arrays hints io ;
IN: benchmark.struct-arrays
STRUCT: point { x float } { y float } { z float } ;
: xyz
[ x>> ] [ y>> ] [ z>> ] tri ; inline
: change-xyz y: z: -- point )
tri-curry [ change-x ] [ change-y ] [ change-z ] tri* ; inline
: init-point
over >fixnum >float
[ sin >>x ] [ cos 3 * >>y ] [ sin sq 2 / >>z ] tri drop
1 + ; inline
: make-points
point <struct-array> dup 0 [ init-point ] reduce drop ; inline
: point-norm
[ xyz [ absq ] tri@ ] sum-outputs sqrt ; inline
: normalize-point
dup point-norm [ / ] [ / ] [ / ] change-xyz drop ; inline
: normalize-points
[ normalize-point ] each ; inline
: max-point
[ x>> max ] [ y>> max ] [ z>> max ] change-xyz ; inline
: <zero-point>
0 0 0 point <struct-boa> ; inline
: max-points
<zero-point> [ max-point ] reduce ; inline
: print-point
[ xyz [ number>string ] tri@ ] output>array ", " join print ; inline
: struct-array-benchmark
make-points [ normalize-points ] [ max-points ] bi print-point ;
HINTS: struct-array-benchmark fixnum ;
: main 5000000 struct-array-benchmark ;
MAIN: main
New Annotation