Skip to content

Commit

Permalink
better output + added a test for ackermann
Browse files Browse the repository at this point in the history
  • Loading branch information
lrz committed Mar 28, 2009
1 parent b0f57d9 commit 2a1049a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion bench.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ def tarai(x, y, z)
end end
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 class Class1
def method1; end def method1; end
def method2(x); x; end def method2(x); x; end
Expand Down Expand Up @@ -61,7 +71,7 @@ def bench_ivar_write(n)


require 'benchmark' require 'benchmark'


Benchmark.bm(3) do |bm| Benchmark.bm(30) do |bm|


# Fixnum arithmetic. # Fixnum arithmetic.
bm.report('10 fib(30)') do bm.report('10 fib(30)') do
Expand All @@ -72,6 +82,7 @@ def bench_ivar_write(n)
end end
bm.report('tak') { tak(18,9,0) } bm.report('tak') { tak(18,9,0) }
bm.report('tarai') { tarai(12,6,0) } bm.report('tarai') { tarai(12,6,0) }
bm.report('ackermann') { ack(3,9) }


# Loops. # Loops.
bm.report('10000000 times loop') do bm.report('10000000 times loop') do
Expand Down

0 comments on commit 2a1049a

Please sign in to comment.