tags:

views:

411

answers:

7

What is the fastest language that runs on the JVM?

Scala? Groovy? JRuby?

+1  A: 

Java.

Really, though, for the most part the speed difference will be negligible. Static languages will be faster than dynamic languages, but not by much.

Anthony Mills
While Java is fastest, it's often by a *huge* amount. Take a look at http://shootout.alioth.debian.org/ and compare JRuby vs Java.
Jim Ferrans
Well look at that. You're right.
Anthony Mills
A: 

Any language that compiles to bytecodes will run equally fast on a JVM with JIT.

Michael Dillon
The massive use of reflection by groovy and ruby make them slower compared to plain java. But according to the JSR-292(http://jcp.org/en/jsr/detail?id=292), that should get better with java 7.
vdr
As far as I know, JRuby is an interpreter, and therefore the Ruby code is not compiled to bytecodes. Doesn't the JIT accomodate for some of the extra work?
Michael Dillon
"Distilling JRuby: The JIT Compiler" http://www.realjenius.com/2009/10/06/distilling-jruby-the-jit-compiler/
igouy
+1  A: 

As Anthony says, Java is the fastest language.

Languages with static typing (Java, Scala) are faster than dynamic ones (Groovy, JRuby).

michael.kebe
+10  A: 

See http://shootout.alioth.debian.org/. Java is very fast, Scala almost as fast. JRuby is 10-30 times slower. Groovy is slow too.

Jim Ferrans
How strange! The text says "http://shootout.alioth.debian.org/" but that isn't where the link takes you...
igouy
igouy
+1  A: 

You have to be careful what you're comparing. As well as the "it depends what you're doing with it" that others have mentioned it also depends how you do it.

For example, a language like Scala can allow you to naturally express idioms and algorithms that you'd probably take a longer way around to do in Java. That's not to say that you couldn't match Scala's performance at doing the same thing - just that it may become an ugly workaround in one language to match the natural idioms in another (note I'm not saying I believe Scala is actually faster than Java at anything specifically - I have no data on that - other than that Scala is designed with scalability in mind - hence the name).

In other words, performance is usually about the algorithms and often the choice of algorithms are about ease of expression. So "use the right tools for the job" applies here - whether that tool happens to be Java, Scala, JRuby or whatever (although I doubt there are any situations where a dynamic language is faster than a static one without being pathological).

Of course we could also talk about profiling before optimising etc, but that doesn't directly address the question.

Phil Nash
"Scala is designed with scalability in mind - hence the name" I don't think that's what they meant by scalable, they meant "concepts scale well to large programs" http://www.scala-lang.org/node/250
igouy
I think it's an overloaded term, but there was definitely an allusion to parallel processing. By making it easier to write concurrent applications they can scale better - and this total performance can improve, even if, per instruction, they are the same or slower.Of course that's not useful for all types of problems.
Phil Nash
"there was definitely an allusion to parallel processing" - in your mind but where do they link that to the name?
igouy
Good question. Just checked and it's not spelt out as clearly as I remembered. However, if you look at scala-lang.org/node/25 and read the section, "The Conception of Scala" you'll see that the language was concieved with architectural scalability as a primary goal. If I find a clear, authoratitive quote that links that back to the name I'll update here. But in the meantime you win this round ;-)
Phil Nash
A: 

I think it would depend on what you mean by faster, and how well the language is written for performance.

For example, if you are doing something math intensive then Scala will be faster than Java.

But, if you avoid functions that are slow in java and use final in all places where it makes sense, you can get Java to run faster than Scala, from what I was told recently at an interview.

So, this is a hard question to answer in generalities, as people will show instances where Scala or Java will be faster.

But, I believe that Scala will generally be faster, if you are not using vars, but val instead.

James Black
"For example, if you are doing something math intensive then Scala will be faster than Java" - can you demonstrate that is true?
igouy
I could, but it will be a while, but due to the design of Scala, if you have a problem that is easy to do in parallel, such as Finite Element Math, then Scala will be faster due to taking advantage of functional programming aspects, but, as I mentioned, you can come up with arguments to show either, it depends on the problem and how well each language was written.
James Black
igouy
@James Black: we're doing performances computing using Java. We considered Scala but it is really slow. The only way to get high-performance using Scala and "array of primitives" (you want that in the Java bytecode generated by Scala) is to use monomorphic Scala arrays. They're kinda ok, but then you have to pay a boxing price for map, projection, etc. Which is a no-no in high-perf performance computing. It's exactly as you wrote in the very next paragraph: Java done correctly is faster. *Especially* for stuff Math intensive. Parallelizing in Java if you know how to do it is very performant.
Webinator
It is difficult to write good multi-threaded code in Java, but since Scala is compiled to Java, it would make sense that Java will be faster, but the ideas from functional programming can be helpful in this, for example, having immutable variables for threads to use. Scala's solution may be easier to implement, more natural, if the problem space is better modeled by functional programming, but it is important to know the limits of the tools and decide which will work best based on your team's skills and constraints.
James Black
+2  A: 

See for yourself -

Current comparison - Java vs Scala vs JRuby

Scala vs JRuby

OUT OF DATE comparison - Java vs CAL vs Nice vs Scala vs JRuby vs Groovy

igouy
+1: These summary views are good.
Jim Ferrans