]> 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 799ef2d46760342d9535295a00cb4d763ad0dead..b0b9e2a04f686a1a0c189d5e65ef86506972bc29 100644 (file)
@@ -1,8 +1,9 @@
 ! 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 } ;
@@ -21,7 +22,7 @@ SPECIALIZED-ARRAY: point
     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
@@ -36,7 +37,7 @@ SPECIALIZED-ARRAY: point
     [ 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
@@ -44,9 +45,10 @@ SPECIALIZED-ARRAY: point
 : 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