Created
April 6, 2012 11:00
-
-
Save anonymous/2318872 to your computer and use it in GitHub Desktop.
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' | |
times = 500000 | |
def gen_string | |
rand(1<<100).to_s(36) | |
end | |
Benchmark.bm(100) do |x| | |
x.report('hashes') { | |
stringhash = {} | |
strings = [] | |
times.times do | |
strings << gen_string | |
stringhash[strings.last.hash] ||= 0 | |
stringhash[strings.last.hash] += 1 | |
end | |
strings.each do |string| | |
stringhash[string.hash] += 1 | |
end | |
} | |
x.report('strings') { | |
stringhash = {} | |
strings = [] | |
times.times do | |
strings << gen_string | |
stringhash[strings.last] ||= 0 | |
stringhash[strings.last] += 1 | |
end | |
strings.each do |string| | |
stringhash[string] += 1 | |
end | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment