Skip to content

Instantly share code, notes, and snippets.

@rafaelss
Created August 5, 2014 19:33
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 rafaelss/f3c8074c8e8b7afb5d3f to your computer and use it in GitHub Desktop.
Save rafaelss/f3c8074c8e8b7afb5d3f to your computer and use it in GitHub Desktop.
require "benchmark/ips"
state1 = :initial
state2 = "initial"
Benchmark.ips do |x|
x.report("case to_s.to_sym") do
case state1.to_s.to_sym
when :initial
a = 1
end
end
x.report("case to_sym.to_s") do
case state2.to_sym.to_s
when "initial"
a = 1
end
end
x.report("case str, sym ") do
case state1
when "initial", :initial
a = 1
end
end
x.report("case sym, str ") do
case state2
when :initial, "initial"
a = 1
end
end
end
Calculating -------------------------------------
case to_s.to_sym 56681 i/100ms
case to_sym.to_s 47407 i/100ms
case str, sym 75357 i/100ms
case sym, str 71288 i/100ms
-------------------------------------------------
case to_s.to_sym 2366810.3 (±15.8%) i/s - 11392881 in 5.012726s
case to_sym.to_s 2011006.9 (±16.6%) i/s - 9623621 in 5.002704s
case str, sym 5926835.7 (±15.4%) i/s - 28409589 in 5.009125s
case sym, str 4393929.6 (±17.4%) i/s - 20816096 in 5.003696s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment