Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Benchmark String and Hash in Ruby
require "benchmark"
precomputed_string = "Very long string value"*100
precomputed_symbol = precomputed_string.to_sym
MAP = {
"key1" => true,
:key2 => true,
precomputed_string => true,
precomputed_symbol => true
} do |x|"string") do
100000.times { MAP["key1"] }
end"symbol") do
100000.times { MAP[:key2] }
end"long string/100") do
100000.times { MAP[precomputed_string] }
end"long symbol") do
100000.times { MAP[precomputed_symbol] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.