From: Robert Klemme Date: 2013-04-03T16:48:51+09:00 Subject: Re: respond_to? vs include? --20cf30050e8ac7d8fd04d97014df Content-Type: text/plain; charset=ISO-8859-1 On Mon, Apr 1, 2013 at 8:26 AM, Edoardo Rossi wrote: > On Mon, Apr 1, 2013 at 12:07 AM, Adam Prescott wrote: > > Your benchmark looks okay. I added a comment to your Gist about a fork > > I made that shows the O(n) behaviour of include? versus the > > constant-time behaviour of respond_to? by just tweaking your code. > Yeah, Array lookup is O(n) - that's what one would expect. But the Array creation has overhead as well. Thank you so much Adam. > Very interesting... appreciated. I think the situation is more dramatic: for a single method test the #instance_methods call needs to be included. https://gist.github.com/rklemme/5299235 Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --20cf30050e8ac7d8fd04d97014df Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Mon, Apr 1, 2013 at 8:26 AM, Edoardo Rossi <= ;edd.rossi@gmail.c= om> wrote:
On Mon, Apr 1, 2013 at 1= 2:07 AM, Adam Prescott <adam@apres= cott.com> wrote:
> Your benchmark looks okay. I added a comment to your Gist about a fork=
> I made that shows the O(n) behaviour of include? versus the
> constant-time behaviour of respond_to? by just tweaking your code.
=

Yeah, Array lookup is O(= n) - that's what one would expect. =A0But the Array creation has overhe= ad as well.

Thank you so much Adam.
Very interesting... appreciated.

I th= ink the situation is more dramatic: for a single method test the #instance_= methods call needs to be included.


Ki= nd regards

robert


-- =
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
--20cf30050e8ac7d8fd04d97014df--