Skip to content

Instantly share code, notes, and snippets.

@Amokrane
Created June 15, 2011 22:28
Show Gist options
  • Save Amokrane/1028288 to your computer and use it in GitHub Desktop.
Save Amokrane/1028288 to your computer and use it in GitHub Desktop.
Benchmarking the fibonacci sequence through an increasing number of iterations. Credit @tenderlove.
require 'benchmark'
def fib n
a = 0
b = 1
n.times { a, b = b, a + b}
a
end
Benchmark.bm(10) do |x|
[1, 10, 100, 1000, 10000].each do |n|
x.report("fib #{n}") do
n.times { fib(1000) }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment