Skip to content

Instantly share code, notes, and snippets.

@matugm
Created February 5, 2018 13:49
Show Gist options
  • Save matugm/410f46ca87455b2701faa9a88edee8df to your computer and use it in GitHub Desktop.
Save matugm/410f46ca87455b2701faa9a88edee8df to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
str = { "foo" => 1 }
sym = { foo: 1 }
Benchmark.ips do |x|
x.report("string") { str["foo"] }
x.report("symbol") { sym[:foo] }
x.compare!
end
#### Results (Ruby 2.4) ####
# Warming up --------------------------------------
# string 153.784k i/100ms
# symbol 180.471k i/100ms
# Calculating -------------------------------------
# string 5.493M (± 3.2%) i/s - 27.527M in 5.016529s
# symbol 9.323M (± 3.8%) i/s - 46.562M in 5.001791s
#
# Comparison:
# symbol: 9323414.3 i/s
# string: 5493159.4 i/s - 1.70x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment