From: "s.ross" Date: 2008-01-17T13:38:02+09:00 Subject: Re: any tricks to speed up ruby? -fwhole-program? --Apple-Mail-4-1046671529 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On Jan 16, 2008, at 7:04 PM, John Carter wrote: > factors up to 2x but usually near 1x for compiler > optimization tweaks This is getting off the Ruby topic, but I think you're being unfair to optimizers (or rather, those who write them). The great thing about optimizers is that we can write clear and expressive code and not worry so much about strength reduction or loop unrolling or all those other things optimizers do for us. Honestly, does it make sense to you to read code like this: a = (a << 1) + 1; -or- a *= 3; The performance difference in a tight loop would be noticeable, but the next person to pick up the code would probably get a quizzical look on his or her face reading it. So the benchmark improvement may be between 1 and 2 percent, but the maintainability improvement could be of far greater benefit. I'm not too familiar with gcc's global opts, but these are the most dangerous, but at the same time least obvious ones. If the optimizer gets it wrong, the code can break in the oddest ways; however, when the optimizer nails a global opt, it can make a difference you might never have predicted. I am truly a fan of compiler optimizations because they fall into the "geez, that really is smart stuff" category. Still, you are absolutely correct that a better algorithm will win almost every time. Just my $.02 :) --Apple-Mail-4-1046671529--