public
Created

Performance comparison: strings vs symbols in Ruby

  • Download Gist
report.txt
1 2 3 4 5 6 7 8 9
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)
symbols-performance.rb
Ruby
1 2 3 4 5 6 7 8
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.