]> gitweb.factorcode.org Git - factor.git/commitdiff
Add some benchmarks
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 24 Aug 2008 08:59:22 +0000 (03:59 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 24 Aug 2008 08:59:22 +0000 (03:59 -0500)
14 files changed:
extra/benchmark/base64/base64.factor [new file with mode: 0644]
extra/benchmark/beust2/beust2.factor
extra/benchmark/binary-search/binary-search.factor [new file with mode: 0644]
extra/benchmark/empty-loop-0/empty-loop-0.factor [new file with mode: 0644]
extra/benchmark/empty-loop-1/empty-loop-1.factor [new file with mode: 0644]
extra/benchmark/empty-loop-2/empty-loop-2.factor [new file with mode: 0644]
extra/benchmark/empty-loop/authors.txt [deleted file]
extra/benchmark/empty-loop/empty-loop.factor [deleted file]
extra/benchmark/mandel/mandel.factor
extra/benchmark/nested-empty-loop-1/nested-empty-loop-1.factor [new file with mode: 0644]
extra/benchmark/nested-empty-loop-2/nested-empty-loop-2.factor [new file with mode: 0644]
extra/benchmark/nsieve-bits/nsieve-bits.factor
extra/benchmark/nsieve/nsieve.factor
extra/benchmark/recursive/recursive.factor

diff --git a/extra/benchmark/base64/base64.factor b/extra/benchmark/base64/base64.factor
new file mode 100644 (file)
index 0000000..f6e5f7c
--- /dev/null
@@ -0,0 +1,11 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: math sequences kernel base64 ;
+IN: benchmark.base64
+
+: base64-benchmark ( -- )
+    65535 [ 255 bitand ] "" map-as
+    100 [ >base64 base64> ] times
+    drop ;
+
+MAIN: base64-benchmark
index 833c1fa77d1784330a0228606f794b4fe97ad49b..2ba6ed9775e9089e7d3bdc6f6f728268fadda2d3 100644 (file)
@@ -5,7 +5,7 @@ IN: benchmark.beust2
 
 ! http://crazybob.org/BeustSequence.java.html
 
-:: (count-numbers) ( remaining first value used max listener -- ? )
+:: (count-numbers) ( remaining first value used max listener: ( -- ) -- ? )
     10 first - [| i |
         [let* | digit [ i first + ]
                 mask [ digit 2^ ]
@@ -26,7 +26,7 @@ IN: benchmark.beust2
                 ] if
             ] [ f ] if
         ]
-    ] contains? ; inline
+    ] contains? ; inline recursive
 
 :: count-numbers ( max listener -- )
     10 [ 1+ 1 1 0 max listener (count-numbers) ] contains? drop ;
diff --git a/extra/benchmark/binary-search/binary-search.factor b/extra/benchmark/binary-search/binary-search.factor
new file mode 100644 (file)
index 0000000..1018e64
--- /dev/null
@@ -0,0 +1,10 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: binary-search math.primes.list math.ranges sequences
+prettyprint ;
+IN: benchmark.binary-search
+
+: binary-search-benchmark ( -- )
+    1 1000000 [a,b] [ primes-under-million sorted-member? ] map length . ;
+
+MAIN: binary-search-benchmark
diff --git a/extra/benchmark/empty-loop-0/empty-loop-0.factor b/extra/benchmark/empty-loop-0/empty-loop-0.factor
new file mode 100644 (file)
index 0000000..65390e8
--- /dev/null
@@ -0,0 +1,10 @@
+USING: math math.private kernel sequences ;
+IN: benchmark.empty-loop-0
+
+: empty-loop-0 ( n -- )
+    dup 0 fixnum< [ drop ] [ 1 fixnum-fast empty-loop-0 ] if ;
+
+: empty-loop-main ( -- )
+    5000000 empty-loop-0 ;
+
+MAIN: empty-loop-main
diff --git a/extra/benchmark/empty-loop-1/empty-loop-1.factor b/extra/benchmark/empty-loop-1/empty-loop-1.factor
new file mode 100644 (file)
index 0000000..36d8722
--- /dev/null
@@ -0,0 +1,10 @@
+USING: math math.private kernel sequences ;
+IN: benchmark.empty-loop-1
+
+: empty-loop-1 ( n -- )
+    [ drop ] each-integer ;
+
+: empty-loop-main ( -- )
+    5000000 empty-loop-1 ;
+
+MAIN: empty-loop-main
diff --git a/extra/benchmark/empty-loop-2/empty-loop-2.factor b/extra/benchmark/empty-loop-2/empty-loop-2.factor
new file mode 100644 (file)
index 0000000..f7d66b0
--- /dev/null
@@ -0,0 +1,10 @@
+USING: math math.private kernel sequences ;
+IN: benchmark.empty-loop-2
+
+: empty-loop-2 ( n -- )
+    [ drop ] each ;
+
+: empty-loop-main ( -- )
+    5000000 empty-loop-2 ;
+
+MAIN: empty-loop-main
diff --git a/extra/benchmark/empty-loop/authors.txt b/extra/benchmark/empty-loop/authors.txt
deleted file mode 100755 (executable)
index 1901f27..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Slava Pestov
diff --git a/extra/benchmark/empty-loop/empty-loop.factor b/extra/benchmark/empty-loop/empty-loop.factor
deleted file mode 100644 (file)
index 2f9f4f3..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-USING: math math.private kernel sequences ;
-IN: benchmark.empty-loop
-
-: empty-loop-0 ( n -- )
-    dup 0 fixnum< [ drop ] [ 1 fixnum-fast empty-loop-0 ] if ;
-
-: empty-loop-1 ( n -- )
-    [ drop ] each-integer ;
-
-: empty-loop-2 ( n -- )
-    [ drop ] each ;
-
-: empty-loop-main ( -- )
-    5000000 empty-loop-0
-    5000000 empty-loop-1
-    5000000 empty-loop-2 ;
-
-MAIN: empty-loop-main
index a81e9565a7fee7a50696c5e5c409e6c283ea9e3f..2685ff28b7c322c07efdbfa77951c218bccaedc9 100755 (executable)
@@ -26,7 +26,7 @@ IN: benchmark.mandel
 
 : iter ( c z nb-iter -- x )
     over absq 4.0 >= over zero? or
-    [ 2nip ] [ 1- >r sq dupd + r> iter ] if ; inline
+    [ 2nip ] [ 1- >r sq dupd + r> iter ] if ; inline recursive
 
 SYMBOL: cols
 
diff --git a/extra/benchmark/nested-empty-loop-1/nested-empty-loop-1.factor b/extra/benchmark/nested-empty-loop-1/nested-empty-loop-1.factor
new file mode 100644 (file)
index 0000000..a7dafee
--- /dev/null
@@ -0,0 +1,29 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: math locals hints ;
+IN: benchmark.nested-empty-loop-1
+
+:: nested-empty-loop ( n -- )
+    n [
+        n [
+            n [
+                n [
+                    n [
+                        n [
+                            n [
+                                n [
+                                    n [ ] times
+                                ] times
+                            ] times
+                        ] times
+                    ] times
+                ] times
+            ] times
+        ] times
+    ] times ;
+
+HINTS: nested-empty-loop fixnum ;
+
+: nested-empty-loop-main ( -- ) 7 nested-empty-loop ;
+
+MAIN: nested-empty-loop-main
diff --git a/extra/benchmark/nested-empty-loop-2/nested-empty-loop-2.factor b/extra/benchmark/nested-empty-loop-2/nested-empty-loop-2.factor
new file mode 100644 (file)
index 0000000..5498067
--- /dev/null
@@ -0,0 +1,31 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel math math.ranges sequences locals hints ;
+IN: benchmark.nested-empty-loop-2
+
+: times ( seq quot -- ) [ drop ] prepose each ; inline
+
+:: nested-empty-loop ( n -- )
+    1 n [a,b] [
+        1 n [a,b] [
+            1 n [a,b] [
+                1 n [a,b] [
+                    1 n [a,b] [
+                        1 n [a,b] [
+                            1 n [a,b] [
+                                1 n [a,b] [
+                                    1 n [a,b] [ ] times
+                                ] times
+                            ] times
+                        ] times
+                    ] times
+                ] times
+            ] times
+        ] times
+    ] times ;
+
+HINTS: nested-empty-loop fixnum ;
+
+: nested-empty-loop-main ( -- ) 7 nested-empty-loop ;
+
+MAIN: nested-empty-loop-main
index 18dced09cc293513b72f53189da3eb490ce2f451..4970b018daa7777de08ea1b7a9239fe800c72e12 100644 (file)
@@ -7,7 +7,7 @@ bit-arrays namespaces io ;
         3drop
     ] [
         f 2over set-nth-unsafe >r over + r> clear-flags
-    ] if ; inline
+    ] if ; inline recursive
 
 : (nsieve-bits) ( count i seq -- count )
     2dup length < [
@@ -17,7 +17,7 @@ bit-arrays namespaces io ;
         ] when >r 1+ r> (nsieve-bits)
     ] [
         2drop
-    ] if ; inline
+    ] if ; inline recursive
 
 : nsieve-bits ( m -- count )
     0 2 rot 1+ <bit-array> dup set-bits (nsieve-bits) ;
index 1e327d901a9b929c2b161eeec0d78ab20dc85964..dd4696232255372f62771c24a65e0f3d9eadf425 100644 (file)
@@ -7,7 +7,7 @@ arrays namespaces io ;
         3drop
     ] [
         f 2over set-nth-unsafe >r over + r> clear-flags
-    ] if ; inline
+    ] if ; inline recursive
 
 : (nsieve) ( count i seq -- count )
     2dup length < [
@@ -17,7 +17,7 @@ arrays namespaces io ;
         ] when >r 1+ r> (nsieve)
     ] [
         2drop
-    ] if ; inline
+    ] if ; inline recursive
 
 : nsieve ( m -- count )
     0 2 rot 1+ t <array> (nsieve) ;
index c8bae8a56ac7e860e1d9e1dd608afc1c2c67e447..128ec571f2293d7969554199a0de008947b15cd7 100755 (executable)
@@ -3,14 +3,14 @@ IN: benchmark.recursive
 
 : fib ( m -- n )
     dup 2 < [ drop 1 ] [ [ 1 - fib ] [ 2 - fib ] bi + ] if ;
-    inline
+    inline recursive
 
 : ack ( m n -- x )
     {
         { [ over zero? ] [ nip 1+ ] }
         { [ dup zero? ] [ drop 1- 1 ack ] }
         [ [ drop 1- ] [ 1- ack ] 2bi ack ]
-    } cond ; inline
+    } cond ; inline recursive
 
 : tak ( x y z -- t )
     2over <= [
@@ -21,7 +21,7 @@ IN: benchmark.recursive
         [      1- -rot tak ]
         3tri
         tak
-    ] if ; inline
+    ] if ; inline recursive
 
 : recursive ( n -- )
     [ 3 swap ack . flush ]