Skip to content

Instantly share code, notes, and snippets.

@DmytroVasin DmytroVasin/hash_size.rb
Last active Jun 17, 2018

Embed
What would you like to do?
Time to add a new key/value pair (ms)
# Ruby -v: 2.3.4
# Chart: https://jsfiddle.net/81ef590x/116/
require 'benchmark'
def without_gc
GC.start
GC.disable
yield
GC.enable
end
170.times do |size|
without_gc do
hashes = []
100000.times do
hash = {}
(1..size).each do
hash[rand] = rand
end
hashes << hash
end
Benchmark.bm do |bench|
bench.report("adding element number #{size+1}") do
100000.times do |n|
hashes[n][size] = rand
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.