Created
February 6, 2013 14:56
-
-
Save rosenfeld/4723061 to your computer and use it in GitHub Desktop.
Performance comparison: strings vs symbols in Ruby
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
ruby symbols-performance.rb | |
Rehearsal ------------------------------------ | |
0.540000 0.010000 0.550000 ( 0.543421) | |
0.680000 0.020000 0.700000 ( 0.705931) | |
--------------------------- total: 1.250000sec | |
user system total real | |
0.240000 0.000000 0.240000 ( 0.244554) | |
0.380000 0.000000 0.380000 ( 0.391517) |
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' | |
hashes = [] | |
1_000_000.times { hashes << { some_key_name: 1, 'some_key_name' => 2 }} | |
Benchmark.bmbm do |x| | |
x.report { hashes.map{|h| h[:some_key_name]} } | |
x.report { hashes.map{|h| h['some_key_name']} } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment