]> gitweb.factorcode.org Git - factor.git/commitdiff
benchmark.mandel: clean up the code a bit without changing performance
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 24 Sep 2009 07:51:43 +0000 (02:51 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 24 Sep 2009 07:51:43 +0000 (02:51 -0500)
- use iota when iterating over integers
- clean up 'c' word

extra/benchmark/mandel/colors/colors.factor
extra/benchmark/mandel/mandel.factor

index 0300538ce101d0f9d3b07df6039a1fc47ccc3345..87a2df6fe545b05a4335ec05e82482efaf63790c 100644 (file)
@@ -1,5 +1,5 @@
 USING: math math.order kernel arrays byte-arrays sequences
-colors.hsv benchmark.mandel.params accessors colors ;
+colors.hsv accessors colors fry benchmark.mandel.params ;
 IN: benchmark.mandel.colors
 
 : scale ( x -- y ) 255 * >fixnum ; inline
@@ -11,10 +11,10 @@ CONSTANT: sat 0.85
 CONSTANT: val 0.85
 
 : <color-map> ( nb-cols -- map )
-    dup [
-        360 * swap 1 + / sat val
+    [ iota ] keep '[
+        360 * _ 1 + / sat val
         1 <hsva> >rgba scale-rgb
-    ] with map ;
+    ] map ;
 
 : color-map ( -- map )
     max-iterations max-color min <color-map> ; foldable
index 1da3d91c61ef4ac7bfa15702ba5140f2b3f6c152..97d700848778c8db6349ae06422f33b034173917 100755 (executable)
@@ -1,4 +1,4 @@
-! Copyright (C) 2005, 2008 Slava Pestov.
+! Copyright (C) 2005, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: io kernel math math.functions sequences prettyprint
 io.files io.files.temp io.encodings io.encodings.ascii
@@ -6,13 +6,12 @@ io.encodings.binary fry benchmark.mandel.params
 benchmark.mandel.colors ;
 IN: benchmark.mandel
 
-: x-inc ( -- x ) width  200000 zoom-fact * / ; inline
-: y-inc ( -- y ) height 150000 zoom-fact * / ; inline
+: x-scale ( -- x ) width  200000 zoom-fact * / ; inline
+: y-scale ( -- y ) height 150000 zoom-fact * / ; inline
 
-: c ( i j -- c )
-    [ x-inc * center real-part x-inc width 2 / * - + >float ]
-    [ y-inc * center imaginary-part y-inc height 2 / * - + >float ] bi*
-    rect> ; inline
+: scale ( x y -- z ) [ x-scale * ] [ y-scale * ] bi* rect> ; inline
+
+: c ( i j -- c ) scale center width height scale 2 / - + ; inline
 
 : count-iterations ( z max-iterations step-quot test-quot -- #iters )
     '[ drop @ dup @ ] find-last-integer nip ; inline
@@ -25,7 +24,7 @@ IN: benchmark.mandel
     [ color-map [ length mod ] keep nth ] [ B{ 0 0 0 } ] if* ; inline
 
 : render ( -- )
-    height [ width swap '[ _ c pixel color write ] each ] each ; inline
+    height iota [ width iota swap '[ _ c pixel color write ] each ] each ; inline
 
 : ppm-header ( -- )
     ascii encode-output