summaryrefslogtreecommitdiff
path: root/jni/ruby/benchmark/other-lang
diff options
context:
space:
mode:
authorJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-16 18:49:26 +0900
committerJari Vetoniemi <jari.vetoniemi@indooratlas.com>2020-03-30 00:39:06 +0900
commitfcbf63e62c627deae76c1b8cb8c0876c536ed811 (patch)
tree64cb17de3f41a2b6fef2368028fbd00349946994 /jni/ruby/benchmark/other-lang
Fresh start
Diffstat (limited to 'jni/ruby/benchmark/other-lang')
-rw-r--r--jni/ruby/benchmark/other-lang/ack.pl11
-rw-r--r--jni/ruby/benchmark/other-lang/ack.py16
-rw-r--r--jni/ruby/benchmark/other-lang/ack.rb12
-rw-r--r--jni/ruby/benchmark/other-lang/ack.scm7
-rw-r--r--jni/ruby/benchmark/other-lang/eval.rb66
-rw-r--r--jni/ruby/benchmark/other-lang/fact.pl13
-rw-r--r--jni/ruby/benchmark/other-lang/fact.py18
-rw-r--r--jni/ruby/benchmark/other-lang/fact.rb13
-rw-r--r--jni/ruby/benchmark/other-lang/fact.scm8
-rw-r--r--jni/ruby/benchmark/other-lang/fib.pl11
-rw-r--r--jni/ruby/benchmark/other-lang/fib.py7
-rw-r--r--jni/ruby/benchmark/other-lang/fib.rb9
-rw-r--r--jni/ruby/benchmark/other-lang/fib.scm7
-rw-r--r--jni/ruby/benchmark/other-lang/loop.pl3
-rw-r--r--jni/ruby/benchmark/other-lang/loop.py2
-rw-r--r--jni/ruby/benchmark/other-lang/loop.rb4
-rw-r--r--jni/ruby/benchmark/other-lang/loop.scm1
-rw-r--r--jni/ruby/benchmark/other-lang/loop2.rb1
-rw-r--r--jni/ruby/benchmark/other-lang/tak.pl11
-rw-r--r--jni/ruby/benchmark/other-lang/tak.py8
-rw-r--r--jni/ruby/benchmark/other-lang/tak.rb13
-rw-r--r--jni/ruby/benchmark/other-lang/tak.scm10
22 files changed, 251 insertions, 0 deletions
diff --git a/jni/ruby/benchmark/other-lang/ack.pl b/jni/ruby/benchmark/other-lang/ack.pl
new file mode 100644
index 0000000..201e22d
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/ack.pl
@@ -0,0 +1,11 @@
+use integer;
+
+sub Ack {
+ return $_[0] ? ($_[1] ? Ack($_[0]-1, Ack($_[0], $_[1]-1))
+ : Ack($_[0]-1, 1))
+ : $_[1]+1;
+}
+
+my $NUM = 9;
+$NUM = 1 if ($NUM < 1);
+my $ack = Ack(3, $NUM);
diff --git a/jni/ruby/benchmark/other-lang/ack.py b/jni/ruby/benchmark/other-lang/ack.py
new file mode 100644
index 0000000..9968e7c
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/ack.py
@@ -0,0 +1,16 @@
+import sys
+sys.setrecursionlimit(5000000)
+
+def Ack(M, N):
+ if (not M):
+ return( N + 1 )
+ if (not N):
+ return( Ack(M-1, 1) )
+ return( Ack(M-1, Ack(M, N-1)) )
+
+def main():
+ NUM = 9
+ sys.setrecursionlimit(10000)
+ Ack(3, NUM)
+
+main()
diff --git a/jni/ruby/benchmark/other-lang/ack.rb b/jni/ruby/benchmark/other-lang/ack.rb
new file mode 100644
index 0000000..7451bed
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/ack.rb
@@ -0,0 +1,12 @@
+def ack(m, n)
+ if m == 0 then
+ n + 1
+ elsif n == 0 then
+ ack(m - 1, 1)
+ else
+ ack(m - 1, ack(m, n - 1))
+ end
+end
+
+NUM = 9
+ack(3, NUM)
diff --git a/jni/ruby/benchmark/other-lang/ack.scm b/jni/ruby/benchmark/other-lang/ack.scm
new file mode 100644
index 0000000..a80b73b
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/ack.scm
@@ -0,0 +1,7 @@
+(define (ack m n)
+ (cond ((zero? m) (+ n 1))
+ ((zero? n) (ack (- m 1) 1))
+ (else (ack (- m 1) (ack m (- n 1))))))
+
+(ack 3 9)
+
diff --git a/jni/ruby/benchmark/other-lang/eval.rb b/jni/ruby/benchmark/other-lang/eval.rb
new file mode 100644
index 0000000..48a2cea
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/eval.rb
@@ -0,0 +1,66 @@
+
+Bench = %w(
+ loop
+ ack
+ fib
+ tak
+ fact
+)
+
+Lang = <<EOP.map{|l| l.strip}
+ ruby-cyg
+ ../../../test6/miniruby
+ perl
+ python
+ gosh
+EOP
+
+Bench.replace ['loop2']
+Lang.replace ['ruby-cyg']
+
+Ext = %w(
+ .rb
+ .rb
+ .pl
+ .py
+ .scm
+)
+
+p Bench
+p Lang
+
+require 'benchmark'
+
+def bench cmd
+ m = Benchmark.measure{
+ #p cmd
+ system(cmd)
+ }
+ [m.utime, m.real]
+end
+
+Result = []
+Bench.each{|b|
+ r = []
+ Lang.each_with_index{|l, idx|
+ cmd = "#{l} #{b}#{Ext[idx]}"
+ r << bench(cmd)
+ }
+ Result << r
+}
+
+require 'pp'
+# utime
+puts Lang.join("\t")
+Bench.each_with_index{|b, bi|
+ print b, "\t"
+ puts Result[bi].map{|e| e[0]}.join("\t")
+}
+
+# rtime
+puts Lang.join("\t")
+Bench.each_with_index{|b, bi|
+ print b, "\t"
+ puts Result[bi].map{|e| e[1]}.join("\t")
+}
+
diff --git a/jni/ruby/benchmark/other-lang/fact.pl b/jni/ruby/benchmark/other-lang/fact.pl
new file mode 100644
index 0000000..a9b0b69
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/fact.pl
@@ -0,0 +1,13 @@
+sub fact{
+ my $n = @_[0];
+ if($n < 2){
+ return 1;
+ }
+ else{
+ return $n * fact($n-1);
+ }
+}
+
+for($i=0; $i<10000; $i++){
+ &fact(100);
+}
diff --git a/jni/ruby/benchmark/other-lang/fact.py b/jni/ruby/benchmark/other-lang/fact.py
new file mode 100644
index 0000000..0159396
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/fact.py
@@ -0,0 +1,18 @@
+#import sys
+#sys.setrecursionlimit(1000)
+
+def factL(n):
+ r = 1
+ for x in range(2, n):
+ r *= x
+ return r
+
+def factR(n):
+ if n < 2:
+ return 1
+ else:
+ return n * factR(n-1)
+
+for i in range(10000):
+ factR(100)
+
diff --git a/jni/ruby/benchmark/other-lang/fact.rb b/jni/ruby/benchmark/other-lang/fact.rb
new file mode 100644
index 0000000..6cedc75
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/fact.rb
@@ -0,0 +1,13 @@
+def fact(n)
+ if n < 2
+ 1
+ else
+ n * fact(n-1)
+ end
+end
+
+i = 0
+while i<10000
+ i += 1
+ fact(100)
+end
diff --git a/jni/ruby/benchmark/other-lang/fact.scm b/jni/ruby/benchmark/other-lang/fact.scm
new file mode 100644
index 0000000..c98a7fe
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/fact.scm
@@ -0,0 +1,8 @@
+(define (fact n)
+ (if (< n 2)
+ 1
+ (* n (fact (- n 1)))))
+
+(dotimes (i 10000)
+ (fact 100))
+
diff --git a/jni/ruby/benchmark/other-lang/fib.pl b/jni/ruby/benchmark/other-lang/fib.pl
new file mode 100644
index 0000000..a46f666
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/fib.pl
@@ -0,0 +1,11 @@
+sub fib{
+ my $n = $_[0];
+ if($n < 3){
+ return 1;
+ }
+ else{
+ return fib($n-1) + fib($n-2);
+ }
+};
+
+&fib(34);
diff --git a/jni/ruby/benchmark/other-lang/fib.py b/jni/ruby/benchmark/other-lang/fib.py
new file mode 100644
index 0000000..45f2bce
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/fib.py
@@ -0,0 +1,7 @@
+def fib(n):
+ if n < 3:
+ return 1
+ else:
+ return fib(n-1) + fib(n-2)
+
+fib(34)
diff --git a/jni/ruby/benchmark/other-lang/fib.rb b/jni/ruby/benchmark/other-lang/fib.rb
new file mode 100644
index 0000000..ec587ea
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/fib.rb
@@ -0,0 +1,9 @@
+def fib n
+ if n < 3
+ 1
+ else
+ fib(n-1) + fib(n-2)
+ end
+end
+
+fib(34)
diff --git a/jni/ruby/benchmark/other-lang/fib.scm b/jni/ruby/benchmark/other-lang/fib.scm
new file mode 100644
index 0000000..2fc4e22
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/fib.scm
@@ -0,0 +1,7 @@
+(define (fib n)
+ (if (< n 3)
+ 1
+ (+ (fib (- n 1)) (fib (- n 2)))))
+
+(fib 34)
+
diff --git a/jni/ruby/benchmark/other-lang/loop.pl b/jni/ruby/benchmark/other-lang/loop.pl
new file mode 100644
index 0000000..2777490
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/loop.pl
@@ -0,0 +1,3 @@
+for($i=0; $i<30000000; $i++){
+}
+
diff --git a/jni/ruby/benchmark/other-lang/loop.py b/jni/ruby/benchmark/other-lang/loop.py
new file mode 100644
index 0000000..003749b
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/loop.py
@@ -0,0 +1,2 @@
+for i in xrange(30000000):
+ pass
diff --git a/jni/ruby/benchmark/other-lang/loop.rb b/jni/ruby/benchmark/other-lang/loop.rb
new file mode 100644
index 0000000..b367b9d
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/loop.rb
@@ -0,0 +1,4 @@
+i = 0
+while i<30000000
+ i += 1
+end
diff --git a/jni/ruby/benchmark/other-lang/loop.scm b/jni/ruby/benchmark/other-lang/loop.scm
new file mode 100644
index 0000000..3364f7e
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/loop.scm
@@ -0,0 +1 @@
+(dotimes (x 30000000))
diff --git a/jni/ruby/benchmark/other-lang/loop2.rb b/jni/ruby/benchmark/other-lang/loop2.rb
new file mode 100644
index 0000000..df8fffc
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/loop2.rb
@@ -0,0 +1 @@
+30000000.times{}
diff --git a/jni/ruby/benchmark/other-lang/tak.pl b/jni/ruby/benchmark/other-lang/tak.pl
new file mode 100644
index 0000000..7e748a6
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/tak.pl
@@ -0,0 +1,11 @@
+sub tak {
+ local($x, $y, $z) = @_;
+ if (!($y < $x)) {
+ return $z;
+ } else {
+ return &tak(&tak($x - 1, $y, $z),
+ &tak($y - 1, $z, $x),
+ &tak($z - 1, $x, $y));
+ }
+}
+&tak(18, 9, 0);
diff --git a/jni/ruby/benchmark/other-lang/tak.py b/jni/ruby/benchmark/other-lang/tak.py
new file mode 100644
index 0000000..04f3f68
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/tak.py
@@ -0,0 +1,8 @@
+def tak(x, y, z):
+ if not(y<x):
+ return z
+ else:
+ return tak(tak(x-1, y, z),
+ tak(y-1, z, x),
+ tak(z-1, x, y))
+tak(18, 9, 0)
diff --git a/jni/ruby/benchmark/other-lang/tak.rb b/jni/ruby/benchmark/other-lang/tak.rb
new file mode 100644
index 0000000..efe5380
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/tak.rb
@@ -0,0 +1,13 @@
+
+def tak x, y, z
+ unless y < x
+ z
+ else
+ tak( tak(x-1, y, z),
+ tak(y-1, z, x),
+ tak(z-1, x, y))
+ end
+end
+
+tak(18, 9, 0)
+
diff --git a/jni/ruby/benchmark/other-lang/tak.scm b/jni/ruby/benchmark/other-lang/tak.scm
new file mode 100644
index 0000000..52a7629
--- /dev/null
+++ b/jni/ruby/benchmark/other-lang/tak.scm
@@ -0,0 +1,10 @@
+(define (tak x y z)
+ (if (not (< y x))
+ z
+ (tak (tak (- x 1) y z)
+ (tak (- y 1) z x)
+ (tak (- z 1) x y))))
+
+(tak 18 9 0)
+
+