Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is faster: MRI Ruby or JRuby?

If I am using Ruby on Rails, should I install MRI/YARV Ruby or JRuby? Which is faster?

like image 249
ses Avatar asked Feb 04 '11 07:02

ses


People also ask

Is JRuby faster than Ruby?

In a 2007 benchmark of Ruby implementations, JRuby was faster than Ruby MRI 1.8 in some tests, but YARV outperformed both of them. As of April 2014, in The Computer Language Benchmarks Game, JRuby 1.7. 4 typically has the same performance as Ruby MRI 2.1. 0, but uses more memory.

Is JRuby fast?

The JVM makes different performance trade-offs than MRI Ruby. Notably, an untuned JVM process has a slow start-up time, and with JRuby, this can get even worse as lots of standard library code is loaded on start-up.

What language is MRI the standard Ruby implementation implemented?

The most commonly used Ruby interpreter is the reference implementation, Ruby MRI, developed in C by the creator of Ruby (Yukihiro Matsumoto) and the Ruby core team.

What is the Ruby interpreter?

A Ruby interpreter is any program that is able to interpret source code written in the Ruby language. Just like you might use different human translators or interpreters, there's not a single version of the Ruby interpreter.


3 Answers

Recent benchmarks put JRuby in the lead, followed by MagLev, Rubinius, then MRI.

Benchmarking is tricky. The Ruby Benchmark Suite is what most use to benchmark Ruby. If you remove any benchmarks that fail across any implementation, you get the following graph.

RBS

Notice I used the geometric mean. This is a better indicator of average performance as it normalizes outliers and machine specs.

The best benchmark you can run will be specific to your app. If you are looking for overall performance, you'll likely want to use real threads, so Rubinius or JRuby are your only real choices.

Also, each implementation is fast at different things. MRI is very fast at starting up, so it's good for scripts. For longer-running applications (like a web application) Rubinius or JRuby will generally perform better than MRI.

like image 68
jc00ke Avatar answered Oct 10 '22 06:10

jc00ke


Actually the answer above is not correct except mikel's answer ,if you observed any benchmark for JVM you'll find it's slow so imagine JRuby's performance compared to CRuby.

Personally I'm an MRI Ruby contributor and I think that the benchmark chart above is not true at all since the introduction of the YARV VM of MRI Ruby , this version became the fastest outthere and lots of benchmarks proved so "See Pat Shaughnessy's benchmarking and comments about the three famous Ruby interpreters MRI Ruby , JRuby and Rubinius". So in my opinion there is no point of comparison due to the following logical points:-

1- C is much faster than Java because it operates directly on Hardware and produces machine code. While JVM produces Bytecode which is considered intermediate code.

2- JRuby contains an additional interpretation step unlike MRI Ruby " Tokenization , Parsing , AST Parsing and generating YARV instructions "Code generation" and finally Code execution" While JRuby contains an additional stage.

3- Garbage collection in MRI Ruby is a lot faster than garbage collection in JRuby even it got better when they introduced some changes in the mark and sweep garbage collection technique.

4- If you surfed most of the companies and technologies used they always used MRI Ruby particularly ruby 1.9 , I rarely saw a company using JRuby or even saw lots of extensions or contributions to it unlike MRI Ruby.

Finally Ruby 1.8 yes it's slower because they were executing code on the AST itself so they used to parse the AST multiple times in order to execute the code.

If I'm wrong at anything I hope anyone corrects me.

Install MRI Ruby dude using RVM or from source. You'll find lots of gems and extensions to work with

like image 3
user3719235 Avatar answered Oct 10 '22 08:10

user3719235


The answer depends on many variables.

But in general, Ruby 1.9 is faster than JRuby, but Ruby 1.8 is slower than JRuby.

e.g. according to the Computer Language Benchmarks Game:

  • Ruby 1.9 vs JRuby
  • Ruby 1.8 vs JRuby

Also, if your application is multi-threaded, JRuby may have some advantages over standard Ruby
(a.k.a. MRI)], depending on how many cores you have.

like image 23
Mikel Avatar answered Oct 10 '22 07:10

Mikel