Forum: JRuby JRuby much slower on this benchmark.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bc77637b2e39fcd4f3e8a6b61d82a2b5?d=identicon&s=25 Jabari Zakiya (jabari_z83)
on 2016-01-11 19:32
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
https://github.com/JuanitoFatas/fast-ruby?utm_sour...

--------------------------------------------------------------
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
Bc77637b2e39fcd4f3e8a6b61d82a2b5?d=identicon&s=25 Jabari Zakiya (jabari_z83)
on 2016-01-11 19:57
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?
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-01-12 08:52
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.
Bc77637b2e39fcd4f3e8a6b61d82a2b5?d=identicon&s=25 Jabari Zakiya (jabari_z83)
on 2016-01-12 21:01
The Java 7 OpenJDK was used on both systems.
Bc77637b2e39fcd4f3e8a6b61d82a2b5?d=identicon&s=25 Jabari Zakiya (jabari_z83)
on 2016-01-12 21:22
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)
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-01-13 08:14
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.
Bc77637b2e39fcd4f3e8a6b61d82a2b5?d=identicon&s=25 Jabari Zakiya (jabari_z83)
on 2016-01-13 17:36
Ronald Fischer 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.
This topic is locked and can not be replied to.