Skip to content

Instantly share code, notes, and snippets.

@evanphx
Created October 19, 2011 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanphx/1297359 to your computer and use it in GitHub Desktop.
Save evanphx/1297359 to your computer and use it in GitHub Desktop.
Fibonacci sequence in Ruby
require 'benchmark'
def fibo(n)
x,y = 0,1
n.times do
x,y = y,x+y
end
end
number = 100_000
printf "\nNumbers of the sequence: #{number}\n"
# warmup
fibo(number)
fibo(number)
puts Benchmark.measure { fibo(number) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment