开发者

High performance calculations with Ruby?

开发者 https://www.devze.com 2023-03-21 01:44 出处:网络
My colleagues normally use C or Fortran for high performance calculations (math on large arrays of data). I wonder if there is any possibility for Ruby code to be compiled/converted and come close to

My colleagues normally use C or Fortran for high performance calculations (math on large arrays of data). I wonder if there is any possibility for Ruby code to be compiled/converted and come close to optimized C code in terms of performance?

There is a number of projects to compile Ruby to bytecode (Rubinius, JRuby, IronRuby, YARV?, Cardinal), and to native code (MacRuby, ..?). What are their chances to get close to C performance?

There is also almost 2-year as inactive project to convert Ruby code to C code: ruby2c.


Related questions:

  • Is it possible to compile Ruby to byte code as with Python?
  • Can Ruby, PHP, or Perl create a pre-compiled file for the code like开发者_Go百科 Python?


There's one option you didn't include: It's rather easy to extend Ruby in C, so if you have a limited set of operations that need to be fast you can write a C extension and then use that from Ruby.

http://people.apache.org/~rooneg/talks/ruby-extensions/ruby-extensions.html


The easiest way to reach C performance level for numerical calculations is to use specialized libraries like Ruby/GSL which are already highly optimized compiled C-code. The final performance will depend how much time your code will spend in the library.


As already mentioned, you're going to want to use high-performance libraries with a ruby wrapper. Don't discount JRuby using java libraries for scientific computing.

0

精彩评论

暂无评论...
验证码 换一张
取 消