From: Mark Hubbart Date: 2004-05-21T23:49:45+09:00 Subject: Re: Ruby's builtin Datastructures On May 20, 2004, at 9:23 AM, Jeff Mitchell wrote: >> Interpretation: it looks like unshift is slightly (~6%) slower than >> pop. shift is barely faster than push. Still, they are all comparable >> in speed. >> >> I ran this test a few times, with similar results. > > But look what happens for larger data, oops. I messed up - I plead sleep deprivation. Here's a different test I ran: create arrays of three different sizes, time various operations on them. Here's the results: Operation Elements Seconds per in Array Operation --------------------------------------- Array#unshift - 10000: 0.00091sec Array#unshift - 100000: 0.02521sec Array#unshift - 1000000: 0.14279sec Array#unshift - 10000000: 1.45725sec Array#shift - 10000: 0.00011sec Array#shift - 100000: 0.00010sec Array#shift - 1000000: 0.00011sec Array#shift - 10000000: 0.00002sec Array#push - 10000: 0.00004sec Array#push - 100000: 0.00011sec Array#push - 1000000: 0.00011sec Array#push - 10000000: 0.44526sec Array#pop - 10000: 0.00003sec Array#pop - 100000: 0.00003sec Array#pop - 1000000: 0.00010sec Array#pop - 10000000: 0.00010sec Array#delete_at - 10000: 0.00122sec Array#delete_at - 100000: 0.01302sec Array#delete_at - 1000000: 0.14309sec Array#delete_at - 10000000: 1.44485sec Array#insert - 10000: 0.00036sec Array#insert - 100000: 0.02693sec Array#insert - 1000000: 0.12566sec Array#insert - 10000000: 3.38137sec I'll let you draw your own conclusions, but it seems fairly simple. cheers, --Mark