Created
August 5, 2014 19:33
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/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 |
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
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