Skip to content

Instantly share code, notes, and snippets.

@ph3nx
Created January 20, 2014 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ph3nx/8527843 to your computer and use it in GitHub Desktop.
Save ph3nx/8527843 to your computer and use it in GitHub Desktop.
Simple Ruby benchmark to benchmark strings and symbols.
require 'benchmark'
string_AZ = Hash[("a".."z").to_a.zip((1..26).to_a)]
symbol_AZ = Hash[(:a..:z).to_a.zip((1..26).to_a)]
string_time = Benchmark.realtime do
100_000.times { string_AZ["r"] }
end
symbol_time = Benchmark.realtime do
100_000.times { symbol_AZ[:r] }
end
puts "String time: #{string_time} seconds."
puts "Symbol time: #{symbol_time} seconds."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment