Created
November 7, 2014 21:40
-
-
Save mmozuras/62c87312eda6201e2ba0 to your computer and use it in GitHub Desktop.
Benchmark hash access in Ruby: symbol versus string
This file contains hidden or 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' | |
string_hash = { 'aaa' => 1, 'bbb' => 2, 'ccc' => 3 } | |
symbol_hash = { aaa: 1, bbb: 2, ccc: 3 } | |
Benchmark.ips do |x| | |
x.report('string') { string_hash['bbb'] } | |
x.report('symbol') { symbol_hash[:bbb] } | |
x.compare! | |
end |
Author
mmozuras
commented
Nov 7, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment