Why is current Ruby (2.3.1) so much slower than current JRuby (9.1.2)?
It’s obviously an implementation differences, but why such a flip flop
in performance from MRI to JRuby?
require ‘benchmark-ips’
a = (1…1000).to_a
Benchmark.ips do |x|
x.report(“block”) { sum=0; a.each {|i| sum += i}; sum }
x.report(“reduce”) { a.reduce(:+) }
x.compare!
end
Results for jruby-9.1.2.0
Warming up --------------------------------------
block 1.056k i/100ms
reduce 2.045k i/100ms
Calculating -------------------------------------
block 12.568k (± 6.1%) i/s - 63.360k in
5.062776s
reduce 21.492k (± 6.6%) i/s - 108.385k in
5.067897s
Comparison:
reduce: 21492.3 i/s
block: 12568.2 i/s - 1.71x slower
Results for ruby-2.3.1
Warming up --------------------------------------
block 1.523k i/100ms
reduce 1.101k i/100ms
Calculating -------------------------------------
block 15.398k (± 5.2%) i/s - 77.673k in
5.059496s
reduce 10.890k (± 4.7%) i/s - 55.050k in
5.067444s
Comparison:
block: 15398.4 i/s
reduce: 10889.9 i/s - 1.41x slower