Skip to content

Instantly share code, notes, and snippets.

@Amokrane
Created June 15, 2011 22:21
Show Gist options
  • Save Amokrane/1028280 to your computer and use it in GitHub Desktop.
Save Amokrane/1028280 to your computer and use it in GitHub Desktop.
Example of using benchmark to measure the fibonnaci algorithm. Credit @tenderlove.
require 'benchmark'
def fib n
a = 0
b = 1
n.times { a, b = b, a + b}
a
end
Benchmark.bm(7) do |x|
x.report("fib") do
3000.times do |i|
fib(1000)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment