Amokrane
6/15/2011 - 10:16 PM

Example of using benchmark to measure the fibonnaci algorithm. Credit @tenderlove.

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