Created
February 6, 2011 07:54
-
-
Save ferrous26/813215 to your computer and use it in GitHub Desktop.
A different version of https://gist.github.com/813190
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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