Skip to content

Instantly share code, notes, and snippets.

@dayvsonlima
Created September 12, 2017 04:34
Show Gist options
  • Save dayvsonlima/a8e9c764dacc83a0f5a3d7a4de84148f to your computer and use it in GitHub Desktop.
Save dayvsonlima/a8e9c764dacc83a0f5a3d7a4de84148f to your computer and use it in GitHub Desktop.
def fib(n)
return n if 1 >= n
fib(n-1) + fib(n-2) if n > 1
end
def fib_include(n)
return n if (0..1).include? n
fib_include(n-1) + fib_include(n-2) if n > 1
end
require 'benchmark'
n = ARGV[0].to_i
Benchmark.bm(8) do |x|
x.report("1 >= n") { fib n }
x.report("include") { fib_include n }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment