Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Created November 20, 2015 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorickpeterse/ec274c38c8160bb1a4a1 to your computer and use it in GitHub Desktop.
Save yorickpeterse/ec274c38c8160bb1a4a1 to your computer and use it in GitHub Desktop.
Calculating -------------------------------------
Array#[] 201.052k i/100ms
Array#at 194.228k i/100ms
-------------------------------------------------
Array#[] 11.090M (± 2.2%) i/s - 55.490M
Array#at 10.003M (± 1.3%) i/s - 50.111M
Comparison:
Array#[]: 11089538.6 i/s
Array#at: 10002944.7 i/s - 1.11x slower
require 'benchmark/ips'
array = (1..1_000_000).to_a
Benchmark.ips do |bench|
bench.report 'Array#[]' do
array[4]
end
bench.report 'Array#at' do
array.at(4)
end
bench.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment