Created
June 17, 2014 19:19
-
-
Save mje113/e9e8582105ad0e46b9b3 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/ips' | |
require 'securerandom' | |
strings = [] | |
500.times { strings << SecureRandom.uuid } | |
string_hash = Hash[strings.zip] | |
sym_hash = Hash[strings.map(&:to_sym).zip] | |
string_key = strings[250] | |
sym_key = strings[250].to_sym | |
Benchmark.ips do |x| | |
x.report('strings') do | |
string_hash[string_key] | |
end | |
x.report('syms') do | |
sym_hash[sym_key] | |
end | |
x.report('string to sym') do | |
sym_hash[string_key.to_sym] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment