Skip to content

Instantly share code, notes, and snippets.

@ferrous26
Created February 6, 2011 07:54
Show Gist options
  • Select an option

  • Save ferrous26/813215 to your computer and use it in GitHub Desktop.

Select an option

Save ferrous26/813215 to your computer and use it in GitHub Desktop.
A different version of https://gist.github.com/813190
require 'benchmark'
array_iterate = (1..10_000_000).to_a
array_shift = array_iterate.dup
Benchmark.bmbm do |test|
# this assumes you can destroy the given array
test.report 'using shift' do
for i in array_shift
array_shift.shift
end
end
test.report 'using an offset' do
for i in array_iterate
array_iterate[i-1]
end
end
test.report 'just accessing an index' do
for i in array_iterate
array_iterate[i]
end
end
test.report 'shifting through duped array' do
new_array = array_iterate.dup
for i in new_array
new_array.shift
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment