Michael Gebhart <mail / miketech.net> wrote:
> d=0
> 1000000000.times {
>   d = d + 1
> }
> 
> puts d

1000000000.times --> 1000000000 method calls to block
d = d + 1        --> 1000000000 method calls to d
puts d	         -->          2 method calls
-----------------------------------------------------
                     2000000002 method calls
=====================================================

Well, it sucks, but I guess you might want to realise that you are
performing *at least* 2000000001 method calls in Ruby, probably *a
factor* more at the C-level implementation, using the above code.

I don't think you can really get around that, since even using a for
loop probably requires that you use a range which might involve more
method calls.

I guess that's the price of pervasive and flexible OO throughout the
language.  I wonder if ruby2c might be able to optimise this sort of
thing.

How does Mono fare when performing 2000000002 method calls?

Cheers,
Navin.