]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/benchmark/struct-arrays/struct-arrays.factor
stomp.cli: simplify
[factor.git] / extra / benchmark / struct-arrays / struct-arrays.factor
index faed2f4dcad3f02e9ec093aacd459fbfbf8baf02..b0b9e2a04f686a1a0c189d5e65ef86506972bc29 100644 (file)
@@ -1,12 +1,15 @@
 ! 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
-struct-arrays io ;
+! 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 } ;
 
+SPECIALIZED-ARRAY: point
+
 : xyz ( point -- x y z )
     [ x>> ] [ y>> ] [ z>> ] tri ; inline
 
@@ -19,7 +22,7 @@ STRUCT: point { x float } { y float } { z float } ;
     1 + ; inline
 
 : make-points ( len -- points )
-    point <struct-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
@@ -34,7 +37,7 @@ STRUCT: point { x float } { y float } { z float } ;
     [ 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
@@ -42,9 +45,10 @@ STRUCT: point { x float } { y float } { z float } ;
 : 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