Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save johnnyshields/4ad359d099576cc2e6fc6914da3e159c to your computer and use it in GitHub Desktop.
Save johnnyshields/4ad359d099576cc2e6fc6914da3e159c to your computer and use it in GitHub Desktop.
Ruby Array vs. Hash creation benchmark
require 'benchmark'
a = 1
b = 2
c = 3
Benchmark.bm do |bm|
bm.report do
10_000_000.times do |a|
[a, b, c]
end
end
bm.report do
10_000_000.times do |a|
{ a: a, b: b, c: c }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment