2006/3/14, Vincent Foley <vfoleybourgon / yahoo.ca>:
> Hello all,
>
> I was working on a little script earlier, which I thought was too slow
> for my taste.  It's now about 5-6x faster than it originally was.
> Normally, this would've been enough, but being very curious about Ruby,
> I tried to make it go even faster by using micro optimizations.  Here
> are some things I found out:
>
> * Running your script with the -rprofile option is the first thing you
> should do

... if it's too slow.

> * Using a Set instead of an Array when you only want to store unique
> values can help make your code go faster

IMHO this is not a micro optimization, this is a changed design. A set
represents something entirely different from an array (although they
share some properties).

> * Disabling the GC can slightly increase the speed of your script.
> However, I don't think it's a good idea to use in larger applications

I don't think either.

> That's a few things I found out today.  Does anyone else have quick
> optimization tips?

In no particular order: Create as few objects as possible. Watch out
where you can in place modifying methods of string vs. non bang
methods. Choose the appropriate abstractions. Don't prematurely
optimize.

Kind regards

robert


--
Have a look: http://www.flickr.com/photos/fussel-foto/