Hi,

On Thu, 17 Aug 2006 23:05:12 +0200, John Lam <drjflam / gmail.com> wrote:

> I was wondering if anyone had taken a look at what % of time that ruby
> spends doing method dispatch?

Here are some numbers. Running this code:

max = 2000
z = x = 0
while (x+=1) <= max
   y = 0
   while (y+=1) <= max
     z = (x+y-z) % 32000
   end
end

takes about 5.5s in plain Ruby 1.8.4 (on my machine).

Compiling it with Ruby2CExtension (latest version, all optimizations  
turned on) and then running it takes about 0.9s.

One of the optimizations is to bypass rb_call and calling the C functions  
of those methods (almost) directly (when possible).

If this optimization is turned off then running the compiled code takes  
about 3.1s. These additional 2.2s are all spent for method dispatch.

Plain Ruby spends at least the same time for method dispatch, so Ruby  
spends at least 40% of the time doing method dispatch (in this case).


I hope that helps,
Dominik