简体   繁体   English

哪个更快:MRI Ruby或JRuby?

[英]Which is faster: MRI Ruby or JRuby?

If I am using Ruby on Rails, should I install MRI/YARV Ruby or JRuby? 如果我使用Ruby on Rails,我应该安装MRI / YARV Ruby还是JRuby? Which is faster? 哪个更快?

Recent benchmarks put JRuby in the lead, followed by MagLev, Rubinius, then MRI. 最近的基准测试使JRuby处于领先地位,其次是MagLev,Rubinius,然后是MRI。

Benchmarking is tricky. 基准测试很棘手。 The Ruby Benchmark Suite is what most use to benchmark Ruby. Ruby Benchmark Suite是最常用于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. 如果你正在寻找整体性能,你可能想要使用真正的线程,所以Rubinius或JRuby是你唯一真正的选择。

Also, each implementation is fast at different things. 此外,每个实现在不同的事情上都很快。 MRI is very fast at starting up, so it's good for scripts. MRI启动速度非常快,因此对脚本有好处。 For longer-running applications (like a web application) Rubinius or JRuby will generally perform better than MRI. 对于运行时间较长的应用程序(如Web应用程序),Rubinius或JRuby通常比MRI更好。

The answer depends on many variables. 答案取决于许多变量。

But in general, Ruby 1.9 is faster than JRuby, but Ruby 1.8 is slower than JRuby. 但总的来说,Ruby 1.9比JRuby快,但Ruby 1.8比JRuby慢。

eg according to the Computer Language Benchmarks Game : 例如根据计算机语言基准游戏

Also, if your application is multi-threaded, JRuby may have some advantages over standard Ruby 此外,如果您的应用程序是多线程的, JRuby可能比标准Ruby有一些优势
(aka MRI)], depending on how many cores you have. (又称MRI)],取决于您拥有多少核心。

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. 实际上上面的答案不正确,除了mikel的答案,如果你观察到任何JVM基准测试,你会发现它很慢,所以想象一下JRuby的性能与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". 就个人而言,我是MRI Ruby的贡献者,我认为自从引入MRI Ruby的YARV VM以来,上面的基准图表并不是真的,这个版本成为最快的,许多基准测试证明了这一点“参见Pat Shaughnessy的基准测试和关于三个着名的Ruby解释器MRI Ruby,JRuby和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. 1- C比Java快得多,因为它直接在硬件上运行并生成机器代码。 While JVM produces Bytecode which is considered intermediate code. 而JVM生成的Bytecode被认为是中间代码。

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. 2- JRuby包含一个额外的解释步骤,不像MRI Ruby“Tokenization,Parsing,AST解析和生成YARV指令”代码生成“,最后是代码执行”,而JRuby包含一个额外的阶段。

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. 3- MRI中的垃圾收集Ruby比JRuby中的垃圾收集要快得多,甚至当它们在标记和扫描垃圾收集技术中引入一些变化时它们也变得更好。

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. 4-如果你浏览大多数使用的公司和技术,他们总是使用MRI Ruby特别是ruby 1.9,我很少看到一家公司使用JRuby,甚至看到很多扩展或贡献,不像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. 最后Ruby 1.8是的,它更慢,因为它们在AST本身上执行代码,因此它们用于多次解析AST以执行代码。

If I'm wrong at anything I hope anyone corrects me. 如果我错了什么,我希望有人纠正我。

Install MRI Ruby dude using RVM or from source. 使用RVM或从源安装MRI Ruby dude。 You'll find lots of gems and extensions to work with 你会发现许多宝石和扩展可以使用

Many users answered already in regards to the benchmarks. 许多用户已经就基准测试回答了问题。 Your question is specifically for the usage with Rails. 您的问题专门针对Rails的使用。

I find it unusual as I don't see clearly the goal of the question. 我觉得这很不寻常,因为我没有清楚地看到问题的目标。 There are many out there using MRI and many using JRuby and many others. 有许多使用MRI,许多人使用JRuby和许多其他人。 I'd go for stability and security and maintainability in that respect, not speed. 我会在这方面寻求稳定性,安全性和可维护性,而不是速度。

However, there is an important difference between MRI and JRuby. 然而,MRI和JRuby之间存在重要差异。

MRI uses a GIL. MRI使用GIL。 This means, although you can have multiple threads, only one thread can be active at a time. 这意味着,虽然您可以拥有多个线程,但一次只能有一个线程处于活动状态。 Also implementation of threads can differ in different Ruby versions. 在不同的Ruby版本中,线程的实现也可能不同。 Newer versions use OS threads (good step forward), older versions use green threads instead. 较新的版本使用操作系统线程(很好的一步),旧版本使用绿色线程。

There is no real parallelism in MRI. MRI中没有真正的并行性。

MRI is multi-threaded, not thread safe and not parallel. MRI是多线程的,不是线程安全的,不是并行的。

JRuby is multi-threaded, not thread safe and parallel. JRuby是多线程的,而不是线程安全和并行的。

Parallelism can make a difference in speed. 并行性可以改变速度。 Both are not thread safe, so you will have to take care of that anyway. 两者都不是线程安全的,所以无论如何你都必须要处理它。 If you look for speed and can exploit parallelism, then I would give JRuby a definite Yes. 如果你寻找速度并且可以利用并行性,那么我会给JRuby一个明确的答案。

Again, I am not sure if speed is the most important factor when deciding between MRI and JRuby. 同样,我不确定在决定MRI和JRuby之间速度是否是最重要的因素。 It is the ecosystem. 这是生态系统。 Since you asked for speed I won't get into this any further. 既然你要求速度我就不会再进一步​​了。

Honestly, it depends on your code. 老实说,这取决于你的代码。 Install RVM or Pik on your machine, install a bunch of different versions of ruby, and try running your code in them. 在您的计算机上安装RVM或Pik,安装一堆不同版本的ruby,并尝试在其中运行您的代码。

For example: An application that frequently restarts is not a great candidate for JRuby since JRuby has some ramp-up time before Hotspot is able to effectively optimize your code. 例如:经常重启的应用程序不是JRuby的理想选择,因为JRuby在Hotspot能够有效优化代码之前有一些加速时间。 Likewise, an application that relies on threads is not a great candidate for Ruby 1.8.7 since Ruby 1.8.X cannot utilize more than 1 core on your processor and thus cannot execute on more than one thread at a time. 同样,依赖于线程的应用程序不是Ruby 1.8.7的理想选择,因为Ruby 1.8.X不能在处理器上使用多于​​1个内核,因此无法一次在多个线程上执行。

There's a really great article done by the guys over at programmingzen.com that compares a lot of the different flavours of ruby. 这些人在programmingzen.com上做了一篇非常棒的文章,比较了很多不同风格的红宝石。 Was published in July last year so still reasonably recent ;) There page compares these: 去年7月发表,所以仍然合理地近期;)那里的页面比较了这些:

* Ruby 1.8.7 p299
* Ruby 1.9.1 p378
* Ruby 1.9.2 RC2
* IronRuby 1.0 (Mono 2.4.4)
* JRuby 1.5.1 (Java HotSpot(TM) 64-Bit Server VM 1.6.0_20)
* MagLev (rev 23832)
* Ruby Enterprise Edition 2010.02
* Rubinius 1.0.1

Might be able to find what you're looking for there 可能能够找到你在那里寻找的东西

http://programmingzen.com/2010/07/19/the-great-ruby-shootout-july-2010/ http://programmingzen.com/2010/07/19/the-great-ruby-shootout-july-2010/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM