]> gitweb.factorcode.org Git - factor.git/commitdiff
Two new benchmarks
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 14 Jul 2008 05:49:09 +0000 (00:49 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 14 Jul 2008 05:49:09 +0000 (00:49 -0500)
extra/benchmark/beust1/beust1.factor [new file with mode: 0644]
extra/benchmark/beust2/beust2.factor [new file with mode: 0644]

diff --git a/extra/benchmark/beust1/beust1.factor b/extra/benchmark/beust1/beust1.factor
new file mode 100644 (file)
index 0000000..9849ac2
--- /dev/null
@@ -0,0 +1,14 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: math.ranges math.parser math.vectors sets sequences
+kernel io ;
+IN: benchmark.beust1
+
+: count-numbers ( max -- n )
+    1 [a,b] [ number>string all-unique? ] count ; inline
+
+: beust ( -- )
+    10000000 count-numbers
+    number>string " unique numbers." append print ;
+
+MAIN: beust
diff --git a/extra/benchmark/beust2/beust2.factor b/extra/benchmark/beust2/beust2.factor
new file mode 100644 (file)
index 0000000..8f794fb
--- /dev/null
@@ -0,0 +1,39 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: math math.ranges math.parser sequences kernel io locals ;
+IN: benchmark.beust2
+
+:: (count-numbers) ( remaining first value used max listener -- ? )
+    10 first - [| i |
+        [let* | digit [ i first + ]
+                mask [ digit 2^ ]
+                value' [ i value + ] |
+            used mask bitand zero? [
+                value max > [ t ] [
+                    remaining 1 <= [
+                        listener call f
+                    ] [
+                        remaining 1-
+                        0
+                        value' 10 *
+                        used mask bitor
+                        max
+                        listener
+                        (count-numbers)
+                    ] if
+                ] if
+            ] [ f ] if
+        ]
+    ] contains? ; inline
+
+:: count-numbers ( max listener -- )
+    10 [ 1+ 1 1 0 max listener (count-numbers) ] contains? drop ;
+    inline
+
+:: beust ( -- )
+    [let | i! [ 0 ] |
+        10000000000 [ i 1+ i! ] count-numbers
+        i number>string " unique numbers." append print
+    ] ;
+
+MAIN: beust