On Sat, Jan 16, 2010 at 6:37 AM, Colin B.
[email protected] wrote:
I think it’s worth reminding people that it’s possible to use Java with JRuby.
On an admittedly low-spec laptop I’ve found that for heavy numeric calculations
(for example calculating CRCs of large files, and for large floating
using JRuby to call Java gives similar performance to compiled FreePascal.
The MRI Zlib.crc32 is written in C (that is correct?) and albeit that is
integer arithmetic, again I’ve found that a JRuby/Java equivalent
has a similar speed.
I’d be interested in any speed tests comparing heavy floating point calculations
with MRI + C extensions and JRuby with Java.
You may as well remove MRI and JRuby from that and look at the many
benchmarks comparing Java and C numeric algorithm performance. In most
cases, you can get close to or equivalent performance from
appropriately-written Java numeric algorithm code (which may or may
not be idiomatic Java code). If you start doing things more OO, then
a better comparison would be equivalent OO-like code in C++, and Java
is still about equivalent.
The cost of calling from (J)Ruby out to Java is probably a bit higher
than calling from Ruby to C extensions, but if you keep the number of
call-outs under control, it’s not going to impact application
And it’s worth pointing out that writing portable Java code is a hell
of a lot easier than writing portable C (especially for backend code
that doesn’t have user-facing UI components); you don’t even need a
compiler on most target systems, and the same code will run anywhere
there’s a Java VM (which is basically anywhere).
If you’d rather not futz with compilers and you’re running on Java 6,
there’s a few useful projects:
- My java-inline project (based on RubyInline), which allows embedding
the Java code directly into your Ruby script:
- My “Duby” language, which attempts to use Ruby syntax to produce
Java code and bytecode without writing in Java:
- My BiteScript project, which is a DSL for generating JVM bytecode
- There’s also a scala-inline which I will (if I haven’t already)
merge into java_inline, allowing you to embed Scala directly into a
All of which can run on any system with a JVM, with or without a