Skip to content

Instantly share code, notes, and snippets.

@masassiez
Created January 26, 2012 09:33
Show Gist options
  • Save masassiez/1681954 to your computer and use it in GitHub Desktop.
Save masassiez/1681954 to your computer and use it in GitHub Desktop.
pik bench fib.rb - VMwareFusion WindowsXP
cache = { 0 => 0, 1 => 1 }
fib = lambda {_fib_ = lambda {|n| cache[n] ||= _fib_[n-2] + _fib_[n-1] } }.call
(1..100000).each { |e| fib[e] }
__END__
ruby 1.8.7 (2011-12-28 patchlevel 357) [i386-mingw32]
Rehearsal ------------------------------------------------------------
** benchmarking 'fib.rb' 2.156000 0.469000 2.625000 ( 2.734410)
--------------------------------------------------- total: 2.625000sec
user system total real
** benchmarking 'fib.rb' 2.156000 0.594000 2.750000 ( 2.781286)
ruby 1.9.2p290 (2011-07-09) [i386-mingw32]
Rehearsal ------------------------------------------------------------
** benchmarking 'fib.rb' 2.234000 0.453000 2.687000 ( 2.703160)
--------------------------------------------------- total: 2.687000sec
user system total real
** benchmarking 'fib.rb' 2.250000 0.813000 3.063000 ( 3.062539)
ruby 1.9.3p0 (2011-10-30) [i386-mingw32]
Rehearsal ------------------------------------------------------------
** benchmarking 'fib.rb' 2.157000 0.500000 2.657000 ( 2.671909)
--------------------------------------------------- total: 2.657000sec
user system total real
** benchmarking 'fib.rb' 2.296000 0.609000 2.905000 ( 2.921912)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment