Last active
August 25, 2019 07:26
-
-
Save evaneykelen/8c455e016afd33447dc33b1c17c887bc to your computer and use it in GitHub Desktop.
`size` vs `count` benchmark
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
require 'benchmark' | |
array = File.readlines('dutch.bin') # 10k lines | |
hash = Hash[*array] # 5k keys => 5k values | |
Benchmark.bmbm do |x| | |
x.report { | |
x.report("Array count") { 10_000.times { array.count } } | |
x.report("Array size") { 10_000.times { array.size } } | |
x.report("Hash count") { 10_000.times { hash.count } } | |
x.report("Hash size") { 10_000.times { hash.size } } | |
} | |
end |
Author
evaneykelen
commented
Aug 25, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment