From: David Garamond Date: 2004-07-03T16:40:43+09:00 Subject: Re: slow method searching? George Ogata wrote: > g@crash:~$ time ruby -e 'a=(1..2000000).to_a; a.classx' > -e:1: undefined method `classx' for # (NoMethodError) > > real 0m6.100s > user 0m5.897s > sys 0m0.104s > g@crash:~$ time ruby -e 'a=(1..2000000).to_a; begin a.classx; rescue NoMethodError; end' > > real 0m0.458s > user 0m0.449s > sys 0m0.008s > > > I'm guessing the time is spent "stringifying" the array when > outputting exception message. Note that for shorter arrays, the array > is actually printed. I guess you're right. $ time ruby -e'a=(1..1000000).to_a; a.classx' -e:1: undefined method `classx' for # (NoMethodError) real 0m19.999s user 0m16.680s sys 0m0.060s $ time ruby -e'a=(1..1000000).to_a; class Array; def inspect; "Array[#{self.length}]" end end; a.classx' -e:1: undefined method `classx' for Array[1000000]:Array (NoMethodError) real 0m0.877s user 0m0.710s sys 0m0.040s So I think what needs to be done is make Array#inspect smarter, right? There's no way a 1-mil element array will have a string representation of < 65 chars. -- dave