Last active
June 17, 2018 11:58
-
-
Save DmytroVasin/666b6ef191161160d258982014ad5e63 to your computer and use it in GitHub Desktop.
Time to add a new key/value pair (ms)
This file contains 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
# 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