Created
February 5, 2018 13:49
-
-
Save matugm/410f46ca87455b2701faa9a88edee8df 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' | |
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