From: Jim Freeze Date: 2005-06-03T06:09:04+09:00 Subject: Re: Interesting discovery... * Joel VanderWerf [2005-06-03 04:43:52 +0900]: > Ara.T.Howard@noaa.gov wrote: > > rescue_test 2.940000 0.320000 3.260000 ( 3.264758) > > respond_to_test 0.160000 0.050000 0.210000 ( 0.208268) > > > > > >looks like respond_to? is indeed faster. > > But if the method *is* defined, rescue is faster: I'm not sure I understand. If the method exists, what is the need for rescue to be called? Are the options being tested these: # with respond_to? if x.respond_to(:meth) x.meth # or x.call(:meth) # or with rescue begin x.meth rescue # no meth So, if meth exists, the only overhead should be the 'if x.respond_to'. If the method does nothing, then a check of this type may appear expensive, but if the method does something, then the 'if' should not be too much of a burden. I suppose that this could be a problem in a tight loop. Under such conditions, it may be better to just rescue. -- Jim Freeze Theory and practice are the same, in theory. -- Ryan Davis