Skip to content

Instantly share code, notes, and snippets.

@mje113
Created June 17, 2014 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mje113/e9e8582105ad0e46b9b3 to your computer and use it in GitHub Desktop.
Save mje113/e9e8582105ad0e46b9b3 to your computer and use it in GitHub Desktop.
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