Created
April 29, 2010 04:02
-
-
Save brntbeer/383114 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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