Brian Candler wrote: > On Thu, May 31, 2007 at 08:12:34AM +0900, Farhad Farzaneh wrote: >> I was playing around with some Ruby features and benchmarked the >> following, showing that making a class call using "self.method" is >> faster than doing the same using "Classname.method". > > By a tiny margin: > > [self.x] >> # user system total real >> # direct 2.230000 0.010000 2.240000 ( 2.313980) >> # send 2.830000 0.020000 2.850000 ( 2.919039) >> # eval 11.440000 0.050000 11.490000 ( 11.667510) > ... > [Klassname.x] >> # user system total real >> # direct 2.360000 0.010000 2.370000 ( 2.395637) >> # send 2.970000 0.010000 2.980000 ( 3.011359) >> # eval 11.460000 0.050000 11.510000 ( 11.651057) > >> Doesn't make much sense to me > > "self" doesn't involve looking up a constant; "Klassname" does. Thanks - actually, I believe that the correct comparison is: [self.x] # user system total real # direct 1.880000 0.010000 1.890000 ( 1.900675) # send 2.460000 0.010000 2.470000 ( 2.509326) # eval 11.440000 0.050000 11.490000 ( 11.688772) [Klassname.x] # user system total real # direct 2.230000 0.010000 2.240000 ( 2.313980) # send 2.830000 0.020000 2.850000 ( 2.919039) # eval 11.440000 0.050000 11.490000 ( 11.667510) As expected, the eval is the same, but in both the send and the direct call method, there is about a 0.35 second difference, which is a substantial percentage. Seems to be an expensive symbol lookup operation... -- Posted via http://www.ruby-forum.com/.