High performance calculations with Ruby?
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.
精彩评论