Skip to content

Instantly share code, notes, and snippets.

@jacksonwillis
Created January 3, 2012 09:41
Show Gist options
  • Save jacksonwillis/1554276 to your computer and use it in GitHub Desktop.
Save jacksonwillis/1554276 to your computer and use it in GitHub Desktop.
Ruby Fibonacci speed tests
ruby 1.8.6 (2009-06-08 patchlevel 369) [x86_64-linux]
user system total real
26.120000 0.000000 26.120000 ( 26.138303)
26.190000 0.000000 26.190000 ( 26.240107)
26.420000 0.000000 26.420000 ( 26.505781)
ruby 2.0.0dev (2012-01-03 trunk 34198) [x86_64-linux]
user system total real
6.830000 0.000000 6.830000 ( 6.852544)
6.820000 0.000000 6.820000 ( 6.833333)
6.580000 0.000000 6.580000 ( 6.581762)
ruby 2.0.0dev (2011-12-26 trunk 34125) [x86_64-linux]
user system total real
6.410000 0.000000 6.410000 ( 6.412703)
6.420000 0.000000 6.420000 ( 6.433833)
6.430000 0.000000 6.430000 ( 6.432210)
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
user system total real
28.280000 0.000000 28.280000 ( 28.286401)
27.830000 0.000000 27.830000 ( 27.845730)
28.920000 0.000000 28.920000 ( 28.929421)
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
user system total real
6.360000 0.010000 6.370000 ( 6.387824)
6.320000 0.010000 6.330000 ( 6.345590)
6.360000 0.000000 6.360000 ( 6.368149)
jruby 1.6.5 (ruby-1.8.7-p330) (2011-10-25 9dcd388) (OpenJDK 64-Bit Server VM 1.6.0_23) [linux-amd64-java]
user system total real
2.849000 0.000000 2.849000 ( 2.713000)
2.140000 0.000000 2.140000 ( 2.140000)
2.143000 0.000000 2.143000 ( 2.143000)
ruby (ree) 1.8.7 (2011-12-28 patchlevel 357) [x86_64-linux]
user system total real
25.450000 0.020000 25.470000 ( 25.670559)
25.240000 0.000000 25.240000 ( 25.258224)
25.300000 0.000000 25.300000 ( 25.436595)
rubinius 2.0.0dev (1.8.7 8ba13d96 yyyy-mm-dd JI) [x86_64-unknown-linux-gnu]
user system total real
5.112320 0.000000 5.112320 ( 5.147931)
4.956310 0.004000 4.960310 ( 4.971012)
5.092318 0.012001 5.104319 ( 5.113250)
require 'benchmark'
def fib(n)
n < 2 ? n : fib(n-1) + fib(n-2)
end
n = 33
Benchmark.bm do |x|
x.report { for i in 1..n; fib(i); end }
x.report { 1.upto(n) { |i| fib(i) } }
x.report { (1..n).each { |i| fib(i) } }
end
rvm all do 'ruby -v; ruby test_speed.rb'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment