Skip to content

Instantly share code, notes, and snippets.

@nahi
Created November 27, 2011 16:01
Show Gist options
  • Save nahi/1397727 to your computer and use it in GitHub Desktop.
Save nahi/1397727 to your computer and use it in GitHub Desktop.
Perf comparison of cast_off gem compiler and JRuby indy branch
% cat bench_fib_recursive.rb
require 'benchmark'
def fib_ruby(n)
if n < 2
n
else
fib_ruby(n - 2) + fib_ruby(n - 1)
end
end
TIMES = (ARGV[0] || 5).to_i
N = (ARGV[1] || 30).to_i
TIMES.times {
puts Benchmark.measure { puts fib_ruby(N) }
}
% ruby -v bench_fib_recursive.rb
ruby 1.9.3p0 (2011-11-08 revision 33661) [x86_64-linux]
832040
0.290000 0.000000 0.290000 ( 0.291377)
832040
0.230000 0.000000 0.230000 ( 0.224458)
832040
0.220000 0.000000 0.220000 ( 0.223801)
832040
0.230000 0.000000 0.230000 ( 0.225720)
832040
0.220000 0.000000 0.220000 ( 0.225394)
% cast_off --run bench_fib_recursive.rb
832040
0.060000 0.000000 0.060000 ( 0.061530)
832040
0.060000 0.000000 0.060000 ( 0.060852)
832040
0.070000 0.000000 0.070000 ( 0.062113)
832040
0.060000 0.000000 0.060000 ( 0.066636)
832040
0.060000 0.000000 0.060000 ( 0.061458)
% jruby -Xcompile.invokedynamic=false bench_fib_recursive.rb
jruby 1.7.0.dev (ruby-1.8.7-p352) (2011-11-27 13ad6d6) (Java HotSpot(TM) 64-Bit Server VM 1.7.0_02-ea) [linux-amd64-java]
832040
0.238000 0.000000 0.238000 ( 0.201000)
832040
0.132000 0.000000 0.132000 ( 0.132000)
832040
0.133000 0.000000 0.133000 ( 0.133000)
832040
0.126000 0.000000 0.126000 ( 0.126000)
832040
0.128000 0.000000 0.128000 ( 0.128000)
% jruby bench_fib_recursive.rb
832040
0.172000 0.000000 0.172000 ( 0.134000)
832040
0.042000 0.000000 0.042000 ( 0.042000)
832040
0.040000 0.000000 0.040000 ( 0.040000)
832040
0.041000 0.000000 0.041000 ( 0.041000)
832040
0.042000 0.000000 0.042000 ( 0.042000)
% cat bm_app_tarai.rb
def tarai( x, y, z )
if x <= y
then y
else tarai(tarai(x-1, y, z),
tarai(y-1, z, x),
tarai(z-1, x, y))
end
end
5.times do
start = Time.now
tarai(12, 6, 0)
p Time.now - start
end
% ruby -v bm_app_tarai.rb
ruby 1.9.3p0 (2011-11-08 revision 33661) [x86_64-linux]
1.304466907
1.046775737
1.05619911
1.034263952
1.018359332
% cast_off --run bm_app_tarai.rb
0.059201368
0.061287277
0.059059633
0.057655381
0.05702261
% jruby -Xcompile.invokedynamic=false bm_app_tarai.rb
jruby 1.7.0.dev (ruby-1.8.7-p352) (2011-11-27 13ad6d6) (Java HotSpot(TM) 64-Bit Server VM 1.7.0_02-ea) [linux-amd64-java]
0.987
0.431
0.43
0.422
0.439
% jruby -v bm_app_tarai.rb
0.339
0.155
0.157
0.159
0.157
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment