Created
September 12, 2017 04:34
-
-
Save dayvsonlima/a8e9c764dacc83a0f5a3d7a4de84148f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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