From: rm_rails@... Date: 2006-04-24T19:53:25+09:00 Subject: Re: array.concat(a) vs array.push(*a) Hmm... perhaps answering my own question .... array.push(*a) segfaults more than concat does.... > > a = [1,2,3,4,5]; puts Benchmark.measure{ (1..20).each{ a.concat(a)}} 0.100000 0.040000 0.140000 ( 0.143773) => nil > > a = [1,2,3,4,5]; puts Benchmark.measure{ (1..20).each{ a.push(*a)}} Segmentation fault On Mon, 24 Apr 2006, rm_rails@cheapcomplexdevices.com wrote: > > > It feels to me like array.concat seems slower than the equivalent (I think) > variation using array.push: > >>> a = [1,2,3,4,5]; b=[]; puts Benchmark.measure{ (1..100000).each{ >>> b.push(*a)}} > 0.090000 0.000000 0.090000 ( 0.090436) > >>> a = [1,2,3,4,5]; b=[]; puts Benchmark.measure{ (1..100000).each{ >>> b.concat(a)}} > 0.290000 0.000000 0.290000 ( 0.296501) > > (using ruby 1.8.4) > > This surprised me somewhat, because earlier > (http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/7521) > it was suggested that concat is a fast way of appending to arrays. > > > Is there something I'm missing, or does it seem I should be > using push(*a) in places where I had been using concat(a)? >