a0rtega
a0rtega

Reputation: 315

Something like Psyco library (Python) for Ruby, exists?

I need more performance in a part of a program, coded in Ruby. In Python i could use Psyco library (that compiles the code, or a part before the execution) to improve the perfromance, but i dont know if exists something like that in Ruby.

Thanks!

Upvotes: 2

Views: 400

Answers (3)

Mark
Mark

Reputation: 477

If you know C you can optimize small parts of the code by just doping to C using rubyinline. I dont know what kind of performance improvements you can expect to see but if you are calling a few c liberys in the c bit of the code instead of ruby you should start to see some big speed ups

require 'inline'

class MyTest

def factorial(n)
   f = 1
   n.downto(2) { |x| f *= x }
   f
end

 inline do |builder|
   builder.c "
   long factorial_c(int max) {
     int i=max, result=1;
     while (i >= 2) { result *= i--; }
     return result;
  }"
 end

end

To get started: sudo gem install RubyInline

Upvotes: 2

Alvaro Talavera
Alvaro Talavera

Reputation: 316

earcar is right

You could update your ruby to 1.9.x, actually all versions of ruby from 1.9, comes with the YARV, that is much more faster than the old ruby interpreter, of course, this is assuming you have installed a previous version.

If you need more speed... you could write you code with c ruby extensions. Here an example..

This would be much much faster, but you have to know to program in c.

Upvotes: 1

Carmine Paolino
Carmine Paolino

Reputation: 2849

I'm thinking no, but you can boost performance using Ruby 1.9.

You must be careful anyway because a lot of things in the language has changed.

Upvotes: 1

Related Questions