Permalink
Browse files

better output + added a test for ackermann

  • Loading branch information...
1 parent b0f57d9 commit 2a1049a19089830a117beaae1e19925e00a33b7b @lrz lrz committed Mar 28, 2009
Showing with 12 additions and 1 deletion.
  1. +12 −1 bench.rb
View
13 bench.rb
@@ -34,6 +34,16 @@ def tarai(x, y, z)
end
end
+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
+
class Class1
def method1; end
def method2(x); x; end
@@ -61,7 +71,7 @@ def bench_ivar_write(n)
require 'benchmark'
-Benchmark.bm(3) do |bm|
+Benchmark.bm(30) do |bm|
# Fixnum arithmetic.
bm.report('10 fib(30)') do
@@ -72,6 +82,7 @@ def bench_ivar_write(n)
end
bm.report('tak') { tak(18,9,0) }
bm.report('tarai') { tarai(12,6,0) }
+ bm.report('ackermann') { ack(3,9) }
# Loops.
bm.report('10000000 times loop') do

0 comments on commit 2a1049a

Please sign in to comment.