Skip to content

Instantly share code, notes, and snippets.

@brntbeer
Created April 29, 2010 04:02
Show Gist options
  • Save brntbeer/383114 to your computer and use it in GitHub Desktop.
Save brntbeer/383114 to your computer and use it in GitHub Desktop.
require 'benchmark'
def fib(n)
if n == 0 || n == 1
n
else
fib(n-1) + fib(n-2)
end
end
(1..100).each do |p| #runs benchmark on fib(36) 30 times.
time = Benchmark.realtime do
1.times do |k|
36.times do |i| #run Fib() up to 36
fib(i)
end
end
end
puts time #uses Benchmark.rb's format to show system time.
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment