From: Charles Oliver Nutter Date: 2010-01-18T07:45:37+09:00 Subject: Re: Float Points error FWIW, I've also just released java-inline 0.0.3, which adds Duby support: {code} require 'rubygems' require 'duby_inline' require 'benchmark' class FastMath def fib_ruby(n) if n < 2 n else fib_ruby(n - 2) + fib_ruby(n - 1) end end inline :Duby do |builder| builder.duby " def fib_duby(n:int) if n < 2 n else fib_duby(n - 2) + fib_duby(n - 1) end end " end end {/code} user system total real fib_ruby(35) 0.306000 0.000000 0.306000 ( 0.306000) fib_ruby(35) 0.302000 0.000000 0.302000 ( 0.302000) fib_ruby(35) 0.302000 0.000000 0.302000 ( 0.302000) fib_ruby(35) 0.302000 0.000000 0.302000 ( 0.302000) fib_ruby(35) 0.303000 0.000000 0.303000 ( 0.303000) fib_duby(35) 0.007000 0.000000 0.007000 ( 0.007000) fib_duby(35) 0.007000 0.000000 0.007000 ( 0.007000) fib_duby(35) 0.007000 0.000000 0.007000 ( 0.007000) fib_duby(35) 0.008000 0.000000 0.008000 ( 0.008000) fib_duby(35) 0.009000 0.000000 0.009000 ( 0.008000) And yes, I appreciate that this looks a little silly since the Duby code is basically the same as the Ruby code. But hey, that's how the _inline thing works. I am interested in adding native support for Duby (or for localized static typing) to JRuby in the future. - Charlie On Sun, Jan 17, 2010 at 4:04 PM, Charles Oliver Nutter wrote: > On Sat, Jan 16, 2010 at 6:37 AM, Colin Bartlett 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 >> point calcs) >> 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 > performance. > > 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: > http://github.com/jruby/java-inline > * My "Duby" language, which attempts to use Ruby syntax to produce > Java code and bytecode without writing in Java: > http://github.com/headius/duby > * My BiteScript project, which is a DSL for generating JVM bytecode > directly: http://github.com/headius/bitescript > * 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 > Ruby script. > > All of which can run on any system with a JVM, with or without a > compiler present. > > - Charlie > >