]> gitweb.factorcode.org Git - factor.git/commitdiff
add benchmarks to cacluate e using decimals, ratios
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 25 Sep 2009 03:11:23 +0000 (22:11 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 25 Sep 2009 03:11:23 +0000 (22:11 -0500)
work/benchmark/e-decimals/authors.txt [new file with mode: 0644]
work/benchmark/e-decimals/e-decimals.factor [new file with mode: 0644]
work/benchmark/e-ratios/authors.txt [new file with mode: 0644]
work/benchmark/e-ratios/e-ratios.factor [new file with mode: 0644]

diff --git a/work/benchmark/e-decimals/authors.txt b/work/benchmark/e-decimals/authors.txt
new file mode 100644 (file)
index 0000000..b4bd0e7
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
\ No newline at end of file
diff --git a/work/benchmark/e-decimals/e-decimals.factor b/work/benchmark/e-decimals/e-decimals.factor
new file mode 100644 (file)
index 0000000..d202e5f
--- /dev/null
@@ -0,0 +1,14 @@
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: decimals kernel locals math math.combinatorics math.ranges
+sequences ;
+IN: benchmark.e-decimals
+
+:: calculate-e-decimals ( n -- e )
+    n [1,b] [ factorial 0 <decimal> D: 1 swap n D/ ] map
+    D: 1 [ D+ ] reduce ;
+
+: calculate-e-decimals-benchmark ( -- )
+    5 [ 800 calculate-e-decimals drop ] times ;
+
+MAIN: calculate-e-decimals-benchmark
diff --git a/work/benchmark/e-ratios/authors.txt b/work/benchmark/e-ratios/authors.txt
new file mode 100644 (file)
index 0000000..b4bd0e7
--- /dev/null
@@ -0,0 +1 @@
+Doug Coleman
\ No newline at end of file
diff --git a/work/benchmark/e-ratios/e-ratios.factor b/work/benchmark/e-ratios/e-ratios.factor
new file mode 100644 (file)
index 0000000..4957822
--- /dev/null
@@ -0,0 +1,12 @@
+! Copyright (C) 2009 Doug Coleman.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel math math.combinatorics math.ranges sequences ;
+IN: benchmark.e-ratios
+
+: calculate-e-ratios ( n -- e )
+    iota [ factorial recip ] sigma ;
+
+: calculate-e-ratios-benchmark ( -- )
+    5 [ 300 calculate-e-ratios drop ] times ;
+
+MAIN: calculate-e-ratios-benchmark