From: George Ogata Date: 2004-07-03T07:37:47+09:00 Subject: Re: slow method searching? David Garamond writes: > Why does it take longer and longer for Ruby to throw NoMethodError for > large arrays? What is going on here? This happens with hash too. Ok, my turn to guess... :) 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. g@crash:~$ time ruby -e 'a=(1..2).to_a; a.classx' -e:1: undefined method `classx' for [1, 2]:Array (NoMethodError) real 0m0.005s user 0m0.003s sys 0m0.001s I don't know what the criteria is for when to print the object and when not to; perhaps it's based on the length of the string in which case the large array is stringified only to have the string thrown away.