JRuby much slower on this benchmark

On the Fast-Ruby site someone submitted a pull request for the benchmark
below. I ran it on JRuby 9.0.4.0, MRI 2.3.0, and Rubinius 2.5.2.
On MRI and Rubinius it produces comparable results (SET.include? is
fastest) but on JRuby the results were opposite (I’m running on Linux on
a 32-bit distros, Lenovo laptop, I5 cpu). Haven’t tried it yet on any of
the VB 64-bit distros I have.

Is this indicative of a bug, or implementation regression?

https://github.com/JuanitoFatas/fast-ruby/pulls


require ‘benchmark/ips’
require ‘set’

ARRAY = (1…100).to_a
SET = (1…100).to_a.to_set
SORTED_SET = SortedSet.new (1…100).to_a

def fast
SET.include?(rand(101))
end

def slow
ARRAY.include?(rand(101))
end

def also_fast
SORTED_SET.include?(rand(101))
end

Benchmark.ips do |x|
x.report(‘Set#include?’) { fast }
x.report(‘SortedSet#include?’) { also_fast }
x.report(‘Array#include?’) { slow }
x.compare!
end

Just ran it on Linux Mint 17.3 KDE 64-bit in VB (Virtual Box) and now
the JRuby 9.0.4.0 results are relatively comparable with MRI 2.3.0 and
RBX 3.3 on the same machine.

Does that mean the 32-bit implementation has a bug, a regression, or it
just is what it is?

Did you use the same Java version?

If yes, maybe could post your findings on the JRuby mailing list, where,
AFIK, several of the maintainers are present.

The Java 7 OpenJDK was used on both systems.

Correction:

Running the command:

$ jruby -rjava -e “puts java.lang.System.get_property(‘java.version’)”

I get: 1.8.0_66 on my 32-bit PCLinuxOS system (host)
and: 1.7.0_91 on 64-bit Linux Mint 17.3 system (VB guest)

Jabari Zakiya wrote in post #1180575:

I get: 1.8.0_66 on my 32-bit PCLinuxOS system (host)
and: 1.7.0_91 on 64-bit Linux Mint 17.3 system (VB guest)

I see. The speed of JRuby is said to depend a lot on the version of the
JVM. 1.8 should be faster than 1.7. Since it is the other way round in
your case, it indeed looks like the difference in speed is attributed to
the 32 vs 64 bit case.

Maybe it would be worth seeing, whether this is due to a JVM on 32 bit
being much slower. If you find the time, you could write a (mostly) pure
Java benchmark, i.e. your JRuby application just invokes a Java method
which then does the benchmark.

Ronald F. wrote in post #1180588:

Maybe it would be worth seeing, whether this is due to a JVM on 32 bit
being much slower. If you find the time, you could write a (mostly) pure
Java benchmark, i.e. your JRuby application just invokes a Java method
which then does the benchmark.

Writing Java code is way beyond my current capabilities, or interest.
I presented these results to alert people (users and devs) to these
benchmark differences.

I suspect there may be a higher interest to make JRuby work best on
64-bit systems than 32-bit, now, but maybe it wouldn’t take too much
work to keep the performance on both platforms comparable.

I’m getting more and more into JRuby 9K, but keep finding these
inconsistencies/differences on 32 vs 64 bit systems that I don’t see
with MRI Ruby.