From: Robert Klemme Date: 2005-06-29T21:50:42+09:00 Subject: Re: yield does not take a block Eric Mahurin wrote: > --- Robert Klemme wrote: >> Note though that yield and &c.call work quite differently. >> This has for example performance implications. > > I didn't know about this advantage. From my quick benchmarks, > I found yield to take half the time as Proc#call in a loop with > the block being empty. I'd imagine the performance difference > is because yield is working with a statically typed Proc, > whereas call is using a normal dynamically typed object to > #call. Yes. More preceisely the overhead of &b.call is in the creation of the proc (i.e. transforming the block, storing the closure and registering the result with GC) - with 'yield' there is no object around. > I'd imagine as ruby matures, the performance difference > between these two would become negligible or zero. Probably but IMHO not very likely. Maybe the gap closes but my guess would be that it remains significant. > I'd hope at > some point ruby would make optimizations when it knows the > exact class of an object - do method lookup at compile time. IMHO this is close to impossible as knowing the class of an object tells you nothing definite about which methods it supports and what signature they have. (see all the discussions about static typing) Kind regards robert