Skip to content

Instantly share code, notes, and snippets.

@tijn
Created March 8, 2012 18:35
Show Gist options
  • Save tijn/2002563 to your computer and use it in GitHub Desktop.
Save tijn/2002563 to your computer and use it in GitHub Desktop.
require 'benchmark'
def do_it(n = 1_000_000)
Benchmark.bm(15) do |bm|
foo = :foo
bm.report("Symbol == Symbol") { n.times { :foo == foo } }
bm.report("to_sym") { n.times { "foo".intern } }
bm.report("hash") { n.times { "foo".hash } }
bar = "bar"
baz = "baz".freeze
bm.report("String == other String") { n.times { "bar" == bar } }
bm.report("same string") { n.times { bar == bar } }
bm.report("String == frozen String") { n.times { "baz" == baz } }
end
end
do_it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment