On Jan 22, 2007, at 15:18, Vincent Fourmond wrote:
> Phrogz wrote:
>> Wolfgang NŠŇasi-Donner wrote:
>>> class Numeric
>>>    def sign
>>>      self<0?-1:self>0?1:0
>>>    end
>>> end
>>>
>>> ...but it should be much faster if be defined in the original class.
>>
>> a) Why do you need it to be so fast? Two comparisons seems pretty
>> lightweight to me!
>
>   You forget function lookup: there is three function lookup for this
> code. Hardcoded in C is way faster (with only one function lookup).

So you've benchmarked it and found that calling Numeric#sign takes up  
a significant part of your runtime?

Note that you can write this in C for about 5 extra lines using  
RubyInline.

-- 
Eric Hodel - drbrain / segment7.net - http://blog.segment7.net

I LIT YOUR GEM ON FIRE!