! Copyright (C) 2009 Slava Pestov.
-! See http://factorcode.org/license.txt for BSD license.
-USING: accessors classes.struct combinators.smart fry kernel
-math math.functions math.order math.parser sequences
+! See https://factorcode.org/license.txt for BSD license.
+USING: accessors alien.data classes.struct combinators.smart
+kernel math math.functions math.order math.parser sequences
specialized-arrays io ;
+FROM: alien.c-types => float ;
IN: benchmark.struct-arrays
STRUCT: point { x float } { y float } { z float } ;
1 + ; inline
: make-points ( len -- points )
- <point-array> dup 0 [ init-point ] reduce drop ; inline
+ point <c-array> dup 0 [ init-point ] reduce drop ; inline
: point-norm ( point -- norm )
[ xyz [ absq ] tri@ ] sum-outputs sqrt ; inline
[ x>> max ] [ y>> max ] [ z>> max ] change-xyz ; inline
: <zero-point> ( -- point )
- 0 0 0 point <struct-boa> ; inline
+ 0 0 0 point boa ; inline
: max-points ( points -- point )
<zero-point> [ max-point ] reduce ; inline
: print-point ( point -- )
[ xyz [ number>string ] tri@ ] output>array ", " join print ; inline
-: struct-array-benchmark ( len -- )
+: struct-arrays-bench ( len -- )
make-points [ normalize-points ] [ max-points ] bi print-point ;
-: main ( -- ) 5000000 struct-array-benchmark ;
+: struct-arrays-benchmark ( -- )
+ 10 [ 500000 struct-arrays-bench ] times ;
-MAIN: main
+MAIN: struct-arrays-benchmark