简体   繁体   English

Ruby vs JRuby vs Java中的多线程

[英]multithreading in Ruby vs JRuby vs Java

I am new to Ruby and the JRuby and I was trying to implement multithreaded code in Ruby and came to know that GIL doesn't allow my code to run in parallel then I moved to JRuby and implemented the same code and my execution time in JRuby was much better than the Ruby. 我是Ruby和JRuby的新手,当时我试图在Ruby中实现多线程代码,后来才知道GIL不允许我的代码并行运行,然后我搬到JRuby并在JRuby中实现了相同的代码和执行时间比Ruby好得多。 I studied that JRuby threading is very much similar to threading in Java, so I implemented the same in code in Java as well and I got a performance(execution time) in Java to be almost 10x faster than JRuby, can someone explain me the reason for this? 我研究了JRuby线程与Java中的线程非常相似,因此我也用Java实现了相同的代码,并且Java中的性能(执行时间)比JRuby快10倍,有人可以解释一下我的原因为了这? Thanks in advance 提前致谢

the explanation is quite simple when you think about JRuby being Ruby implemented in Java, which means that you have 'more' Java code to execute using the .rb piece compared to plain .java compiled to a .class ... 当您想到JRuby是用Java实现的Ruby时,解释就很简单,这意味着与将普通.java编译为.class相比,您可以使用.rb块来执行更多的Java代码。

than even if the method dispatch was cost-less there's the dynamic nature of Ruby eg when you a+1 on Java it adding to ints while a+1 in Ruby its an addition with overflow checks etc. 比即使该方法的派遣是成本更低还有如红宝石的动态特性,当你a+1上的Java将它添加到整数,而a+1在Ruby中的加法与溢出检查等。

your question is quite general and we also do not know what kind of performance measuring you did but in the end it all comes down to productivity when you do 'real-world' work + with JRuby if you feel like some part is worth being 10x faster you still have the option of re-doing that piece in "native" Java. 您的问题很笼统,我们也不知道您对性能进行了什么样的评估,但是最终,当您进行“现实世界”的工作+使用JRuby进行工作时,如果您觉得某个部分的价值是10倍,那么一切都将取决于生产力。更快,您仍然可以选择在“本机” Java中重做该部分。

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

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