Was curious about how fast method lookup was in Ruby under various
circumstances. So I wrote this samll stress test. It included moudle
within module up $n deep and times a method call to the middle of it
all. Interestingly it words fine at 1000 levels deep, takingless then a
second to generate the modules, but make it 10000 and instead of just
taking 10 times longer, my system comes to it's knees. I assume it has
to do with memory use. I have 512 MB of RAM, do modules/classes really
eat that much memory?

  $n = 1000  # try 10000

  puts "Generating #{$n} cascading modules..."

  $m = []
  (1..$n).each { |i|
    $m[i] = Module.new
    $m[i].class_eval {
      define_method( "_#{i}" ) { puts "Called method in module #{i}." }
      include $m[i-1] if $m[i-1]
    }
  }

  class ManyIncludes
    include $m[$n]
  end

  mm = ManyIncludes.new
  mn = "_#{$n/2}"

  t0 = Time.now
  mm.send(mn)
  t1 = Time.now
  puts "Time to call a single method among #{$n} modules: #{(t1 -
t0).to_f} seconds."

T.