From: Robert Dober Date: 2007-07-24T22:16:15+09:00 Subject: Re: Static variables in Ruby. On 7/24/07, Jeremy Henty wrote: > On 2007-07-24, Robert Dober wrote: > > On 7/24/07, Jeremy Henty wrote: > >> > >> class Foo > >> count = 0 > >> define_method(:foo) { count += 1 } > >> end > > > > Terribly slow BTW :( > > Why is that? Are all methods created by define_method slow? Or is it > something particular to the way I'm using it here? I'm really getting > into metaprogramming with define_method so I'd like to learn about the > pitfalls. > > Regards, > > Jeremy Henty > > No it is the lookup, if you are interested I can send you my benchmarks, without any twists it was 4 to 5 times slower than ivar lookup and with twists like read_only, write_once, rw_locks it quickly climbed to a factor worse than 10 :( Robert -- I always knew that one day Smalltalk would replace Java. I just didn't know it would be called Ruby -- Kent Beck