Update benchmarks for specialized arrays

db4
Slava Pestov 2008-12-03 00:05:54 -06:00
parent 66c53b573d
commit 0dceb4c664
6 changed files with 38 additions and 38 deletions

View File

@ -1,5 +1,5 @@
USING: make math sequences splitting grouping USING: make math sequences splitting grouping
kernel columns float-arrays bit-arrays ; kernel columns specialized-arrays.double bit-arrays ;
IN: benchmark.dispatch2 IN: benchmark.dispatch2
: sequences ( -- seq ) : sequences ( -- seq )
@ -10,7 +10,7 @@ IN: benchmark.dispatch2
"hello world" , "hello world" ,
SBUF" sbuf world" , SBUF" sbuf world" ,
V{ "a" "b" "c" } , V{ "a" "b" "c" } ,
F{ 1.0 2.0 3.0 } , double-array{ 1.0 2.0 3.0 } ,
"hello world" 4 tail-slice , "hello world" 4 tail-slice ,
10 f <repetition> , 10 f <repetition> ,
100 2 <sliced-groups> , 100 2 <sliced-groups> ,

View File

@ -1,6 +1,6 @@
USING: sequences math mirrors splitting grouping USING: sequences math mirrors splitting grouping
kernel make assocs alien.syntax columns kernel make assocs alien.syntax columns
float-arrays bit-arrays ; specialized-arrays.double bit-arrays ;
IN: benchmark.dispatch3 IN: benchmark.dispatch3
GENERIC: g ( obj -- str ) GENERIC: g ( obj -- str )
@ -26,7 +26,7 @@ M: object g drop "object" ;
"hello world" , "hello world" ,
SBUF" sbuf world" , SBUF" sbuf world" ,
V{ "a" "b" "c" } , V{ "a" "b" "c" } ,
F{ 1.0 2.0 3.0 } , double-array{ 1.0 2.0 3.0 } ,
"hello world" 4 tail-slice , "hello world" 4 tail-slice ,
10 f <repetition> , 10 f <repetition> ,
100 2 <sliced-groups> , 100 2 <sliced-groups> ,

View File

@ -1,7 +1,7 @@
! Based on http://shootout.alioth.debian.org/gp4/benchmark.php?test=fasta&lang=java&id=2 ! Based on http://shootout.alioth.debian.org/gp4/benchmark.php?test=fasta&lang=java&id=2
USING: math kernel io io.files locals multiline assocs sequences USING: math kernel io io.files locals multiline assocs sequences
sequences.private benchmark.reverse-complement hints io.encodings.ascii sequences.private benchmark.reverse-complement hints io.encodings.ascii
byte-arrays float-arrays ; byte-arrays specialized-arrays.double ;
IN: benchmark.fasta IN: benchmark.fasta
: IM 139968 ; inline : IM 139968 ; inline
@ -49,7 +49,7 @@ HINTS: random fixnum ;
: make-cumulative ( freq -- chars floats ) : make-cumulative ( freq -- chars floats )
dup keys >byte-array dup keys >byte-array
swap values >float-array unclip [ + ] accumulate swap suffix ; swap values >double-array unclip [ + ] accumulate swap suffix ;
:: select-random ( seed chars floats -- seed elt ) :: select-random ( seed chars floats -- seed elt )
floats seed random -rot floats seed random -rot

View File

@ -1,6 +1,6 @@
! Copyright (C) 2008 Slava Pestov. ! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors float-arrays fry kernel locals make math USING: accessors specialized-arrays.double fry kernel locals make math
math.constants math.functions math.vectors prettyprint math.constants math.functions math.vectors prettyprint
sequences hints arrays ; sequences hints arrays ;
IN: benchmark.nbody IN: benchmark.nbody
@ -9,39 +9,39 @@ IN: benchmark.nbody
: days-per-year 365.24 ; inline : days-per-year 365.24 ; inline
TUPLE: body TUPLE: body
{ location float-array } { location double-array }
{ velocity float-array } { velocity double-array }
{ mass float read-only } ; { mass float read-only } ;
: <body> ( location velocity mass -- body ) : <body> ( location velocity mass -- body )
[ days-per-year v*n ] [ solar-mass * ] bi* body boa ; inline [ days-per-year v*n ] [ solar-mass * ] bi* body boa ; inline
: <jupiter> ( -- body ) : <jupiter> ( -- body )
F{ 4.84143144246472090e+00 -1.16032004402742839e+00 -1.03622044471123109e-01 } double-array{ 4.84143144246472090e+00 -1.16032004402742839e+00 -1.03622044471123109e-01 }
F{ 1.66007664274403694e-03 7.69901118419740425e-03 -6.90460016972063023e-05 } double-array{ 1.66007664274403694e-03 7.69901118419740425e-03 -6.90460016972063023e-05 }
9.54791938424326609e-04 9.54791938424326609e-04
<body> ; <body> ;
: <saturn> ( -- body ) : <saturn> ( -- body )
F{ 8.34336671824457987e+00 4.12479856412430479e+00 -4.03523417114321381e-01 } double-array{ 8.34336671824457987e+00 4.12479856412430479e+00 -4.03523417114321381e-01 }
F{ -2.76742510726862411e-03 4.99852801234917238e-03 2.30417297573763929e-05 } double-array{ -2.76742510726862411e-03 4.99852801234917238e-03 2.30417297573763929e-05 }
2.85885980666130812e-04 2.85885980666130812e-04
<body> ; <body> ;
: <uranus> ( -- body ) : <uranus> ( -- body )
F{ 1.28943695621391310e+01 -1.51111514016986312e+01 -2.23307578892655734e-01 } double-array{ 1.28943695621391310e+01 -1.51111514016986312e+01 -2.23307578892655734e-01 }
F{ 2.96460137564761618e-03 2.37847173959480950e-03 -2.96589568540237556e-05 } double-array{ 2.96460137564761618e-03 2.37847173959480950e-03 -2.96589568540237556e-05 }
4.36624404335156298e-05 4.36624404335156298e-05
<body> ; <body> ;
: <neptune> ( -- body ) : <neptune> ( -- body )
F{ 1.53796971148509165e+01 -2.59193146099879641e+01 1.79258772950371181e-01 } double-array{ 1.53796971148509165e+01 -2.59193146099879641e+01 1.79258772950371181e-01 }
F{ 2.68067772490389322e-03 1.62824170038242295e-03 -9.51592254519715870e-05 } double-array{ 2.68067772490389322e-03 1.62824170038242295e-03 -9.51592254519715870e-05 }
5.15138902046611451e-05 5.15138902046611451e-05
<body> ; <body> ;
: <sun> ( -- body ) : <sun> ( -- body )
F{ 0 0 0 } F{ 0 0 0 } 1 <body> ; double-array{ 0 0 0 } double-array{ 0 0 0 } 1 <body> ;
: offset-momentum ( body offset -- body ) : offset-momentum ( body offset -- body )
vneg solar-mass v/n >>velocity ; inline vneg solar-mass v/n >>velocity ; inline
@ -49,7 +49,7 @@ TUPLE: body
TUPLE: nbody-system { bodies array read-only } ; TUPLE: nbody-system { bodies array read-only } ;
: init-bodies ( bodies -- ) : init-bodies ( bodies -- )
[ first ] [ F{ 0 0 0 } [ [ velocity>> ] [ mass>> ] bi v*n v+ ] reduce ] bi [ first ] [ double-array{ 0 0 0 } [ [ velocity>> ] [ mass>> ] bi v*n v+ ] reduce ] bi
offset-momentum drop ; inline offset-momentum drop ; inline
: <nbody-system> ( -- system ) : <nbody-system> ( -- system )

View File

@ -1,7 +1,7 @@
! Factor port of the raytracer benchmark from ! Factor port of the raytracer benchmark from
! http://www.ffconsultancy.com/free/ray_tracer/languages.html ! http://www.ffconsultancy.com/free/ray_tracer/languages.html
USING: arrays accessors float-arrays io io.files USING: arrays accessors specialized-arrays.double io io.files
io.encodings.binary kernel math math.functions math.vectors io.encodings.binary kernel math math.functions math.vectors
math.parser make sequences sequences.private words hints ; math.parser make sequences sequences.private words hints ;
IN: benchmark.raytracer IN: benchmark.raytracer
@ -9,7 +9,7 @@ IN: benchmark.raytracer
! parameters ! parameters
: light : light
#! Normalized { -1 -3 2 }. #! Normalized { -1 -3 2 }.
F{ double-array{
-0.2672612419124244 -0.2672612419124244
-0.8017837257372732 -0.8017837257372732
0.5345224838248488 0.5345224838248488
@ -23,17 +23,17 @@ IN: benchmark.raytracer
: delta 1.4901161193847656E-8 ; inline : delta 1.4901161193847656E-8 ; inline
TUPLE: ray { orig float-array read-only } { dir float-array read-only } ; TUPLE: ray { orig double-array read-only } { dir double-array read-only } ;
C: <ray> ray C: <ray> ray
TUPLE: hit { normal float-array read-only } { lambda float read-only } ; TUPLE: hit { normal double-array read-only } { lambda float read-only } ;
C: <hit> hit C: <hit> hit
GENERIC: intersect-scene ( hit ray scene -- hit ) GENERIC: intersect-scene ( hit ray scene -- hit )
TUPLE: sphere { center float-array read-only } { radius float read-only } ; TUPLE: sphere { center double-array read-only } { radius float read-only } ;
C: <sphere> sphere C: <sphere> sphere
@ -87,7 +87,7 @@ TUPLE: group < sphere { objs array read-only } ;
M: group intersect-scene ( hit ray group -- hit ) M: group intersect-scene ( hit ray group -- hit )
[ drop objs>> [ intersect-scene ] with each ] if-ray-sphere ; [ drop objs>> [ intersect-scene ] with each ] if-ray-sphere ;
: initial-hit T{ hit f F{ 0.0 0.0 0.0 } 1/0. } ; inline : initial-hit T{ hit f double-array{ 0.0 0.0 0.0 } 1/0. } ; inline
: initial-intersect ( ray scene -- hit ) : initial-intersect ( ray scene -- hit )
[ initial-hit ] 2dip intersect-scene ; inline [ initial-hit ] 2dip intersect-scene ; inline
@ -120,10 +120,10 @@ DEFER: create ( level c r -- scene )
: create-offsets ( quot -- ) : create-offsets ( quot -- )
{ {
F{ -1.0 1.0 -1.0 } double-array{ -1.0 1.0 -1.0 }
F{ 1.0 1.0 -1.0 } double-array{ 1.0 1.0 -1.0 }
F{ -1.0 1.0 1.0 } double-array{ -1.0 1.0 1.0 }
F{ 1.0 1.0 1.0 } double-array{ 1.0 1.0 1.0 }
} swap each ; inline } swap each ; inline
: create-bound ( c r -- sphere ) 3.0 * <sphere> ; : create-bound ( c r -- sphere ) 3.0 * <sphere> ;
@ -138,14 +138,14 @@ DEFER: create ( level c r -- scene )
pick 1 = [ <sphere> nip ] [ create-group ] if ; pick 1 = [ <sphere> nip ] [ create-group ] if ;
: ss-point ( dx dy -- point ) : ss-point ( dx dy -- point )
[ oversampling /f ] bi@ 0.0 3float-array ; [ oversampling /f ] bi@ 0.0 double-array{ } 3sequence ;
: ss-grid ( -- ss-grid ) : ss-grid ( -- ss-grid )
oversampling [ oversampling [ ss-point ] with map ] map ; oversampling [ oversampling [ ss-point ] with map ] map ;
: ray-grid ( point ss-grid -- ray-grid ) : ray-grid ( point ss-grid -- ray-grid )
[ [
[ v+ normalize F{ 0.0 0.0 -4.0 } swap <ray> ] with map [ v+ normalize double-array{ 0.0 0.0 -4.0 } swap <ray> ] with map
] with map ; ] with map ;
: ray-pixel ( scene point -- n ) : ray-pixel ( scene point -- n )
@ -156,7 +156,7 @@ DEFER: create ( level c r -- scene )
size reverse [ size reverse [
size [ size [
[ size 0.5 * - ] bi@ swap size [ size 0.5 * - ] bi@ swap size
3float-array double-array{ } 3sequence
] with map ] with map
] map ; ] map ;
@ -169,7 +169,7 @@ DEFER: create ( level c r -- scene )
pixel-grid [ [ ray-pixel ] with map ] with map ; pixel-grid [ [ ray-pixel ] with map ] with map ;
: run ( -- string ) : run ( -- string )
levels F{ 0.0 -1.0 0.0 } 1.0 create ray-trace [ levels double-array{ 0.0 -1.0 0.0 } 1.0 create ray-trace [
size size pgm-header size size pgm-header
[ [ oversampling sq / pgm-pixel ] each ] each [ [ oversampling sq / pgm-pixel ] each ] each
] B{ } make ; ] B{ } make ;

View File

@ -1,8 +1,8 @@
! Factor port of ! Factor port of
! http://shootout.alioth.debian.org/gp4/benchmark.php?test=spectralnorm&lang=all ! http://shootout.alioth.debian.org/gp4/benchmark.php?test=spectralnorm&lang=all
USING: float-arrays kernel math math.functions math.vectors USING: specialized-arrays.double kernel math math.functions
sequences sequences.private prettyprint words math.vectors sequences sequences.private prettyprint words hints
hints locals ; locals ;
IN: benchmark.spectral-norm IN: benchmark.spectral-norm
:: inner-loop ( u n quot -- seq ) :: inner-loop ( u n quot -- seq )
@ -10,7 +10,7 @@ IN: benchmark.spectral-norm
n 0.0 [| j | n 0.0 [| j |
u i j quot call + u i j quot call +
] reduce ] reduce
] F{ } map-as ; inline ] double-array{ } map-as ; inline
: eval-A ( i j -- n ) : eval-A ( i j -- n )
[ >float ] bi@ [ >float ] bi@
@ -32,7 +32,7 @@ IN: benchmark.spectral-norm
: eval-AtA-times-u ( u n -- seq ) : eval-AtA-times-u ( u n -- seq )
[ eval-A-times-u ] [ eval-At-times-u ] bi ; inline [ eval-A-times-u ] [ eval-At-times-u ] bi ; inline
: ones ( n -- seq ) [ 1.0 ] F{ } replicate-as ; inline : ones ( n -- seq ) [ 1.0 ] double-array{ } replicate-as ; inline
:: u/v ( n -- u v ) :: u/v ( n -- u v )
n ones dup n ones dup