From: Kyle Schmitt Date: 2008-09-24T02:09:19+09:00 Subject: Re: Breaking apart arrays for arguments? On Tue, Sep 23, 2008 at 11:41 AM, Thomas B. wrote: > Hello. It's the splat operator: > > meth(*args_array) Thanks. Evidence there isn't enough coffee in my office :) Although it's odd. I would have expected using the splat operator to provide better performance than flatten, doesn't seem to be the case. I guess I need to read up on the underpinnings of ruby's splat. require 'benchmark' $size=1024 $runs=1024 Benchmark.bm do |bm| bm.report("unshift pure") do unshifter=Array.new($size){0} 1.upto($runs) do |index| unshifter.unshift(*Array.new($size){index}) end end bm.report("unshift, flatten at end") do unshifter=Array.new($size){0} 1.upto($runs) do |index| unshifter.unshift(Array.new($size){index}) end unshifter.flatten! end end user system total real unshift pure 4.060000 0.660000 4.720000 ( 5.908041) unshift, flatten at end 1.660000 0.550000 2.210000 ( 2.431595)