From: "NARUSE, Yui" Date: 2011-06-24T03:56:45+09:00 Subject: [ruby-core:37331] Re: [Ruby 1.9 - Feature #4917][Rejected] NilClass#to_ary (2011/06/24 1:00), Benoit Daloze wrote: > On 22 June 2011 19:55, Marc-Andre Lafortune wrote: >> The method `to_ary` is for classes that can be implicitly converted to an Array. This doesn't apply to NilClass. nil is not an array; NilClass can't have to_ary. >> I'm also highly sceptical as to the actual real life impact of such an optimization. > > I agree with you, such optimization is not worth it. > > But, for the sake of curiosity, I did my own benchmark. > The numbers are (optArray doing the nil check, for 1 000 000 calls): > Array(nil) 0.487444 > optArray(nil) 0.234128 > > Array(Object.new) 0.462688 > optArray(Object.new) 0.467910 > > It is 2 times faster for nil, and does not seem to impact the > performance for other objects. > > But the real gain is 0.2s on 1 million calls, which should never > happen in real life (or then it would be insignificant compared to the > total time to run). It needs a check whether NilClass#to_a is redefined or not. -- NARUSE, Yui