From: Ara.T.Howard@... Date: 2005-06-03T05:20:24+09:00 Subject: Re: Interesting discovery... On Fri, 3 Jun 2005, Joel VanderWerf wrote: > Ara.T.Howard@noaa.gov wrote: > >> Benchmark::bm do |b| >> %w(rescue_test respond_to_test).map{|m| b.report(m){c.send m,n}} >> end >> >> >> harp:~ > ruby a.rb >> user system total real >> 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: > > class C > def a; end # <== added > def c; end > ... > > > user system total real > rescue_test 0.070000 0.000000 0.070000 ( 0.072631) > respond_to_test 0.130000 0.010000 0.140000 ( 0.140980) > > > So, if some obejcts have the methods and some dont, the best choice > depends on the balance between the two branches (defined vs. undefined). very true - i hadn't thought of that... thanks. -a -- =============================================================================== | email :: ara [dot] t [dot] howard [at] noaa [dot] gov | phone :: 303.497.6469 | My religion is very simple. My religion is kindness. | --Tenzin Gyatso ===============================================================================