Last active
December 11, 2015 01:58
-
-
Save nilbus/4526647 to your computer and use it in GitHub Desktop.
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
# Benchmarks for https://github.com/rails/rails/pull/8914 | |
require 'bench_press' | |
extend BenchPress | |
def original | |
headers = "requiresActiveX=true" | |
new_header = "IE=Edge,chrome=1" | |
headers << "," << new_header | |
end | |
def fixed_with_split | |
headers = "requiresActiveY=true" | |
new_header = "IE=Edgy,chrome=1" | |
new_header.split(',').each do |component| | |
unless headers[component] | |
headers << "," << component | |
end | |
end | |
end | |
def fixed_without_split | |
headers = "requiresActiveZ=true" | |
new_header = ["IE=Iffy", "chrome=2"] | |
new_header.each do |component| | |
unless headers[component] | |
headers << "," << component | |
end | |
end | |
end | |
def fixed_without_loop | |
headers = "requiresActiveZ=true" | |
new_header = "IE=Edgy,chrome=1" | |
unless headers[new_header] | |
headers << "," << new_header | |
end | |
end | |
def fixed_using_index | |
headers = "requiresActiveZ=true" | |
new_header = "IE=Edgy,chrome=1" | |
unless headers.index(new_header) | |
headers << "," << new_header | |
end | |
end | |
reps 500000 | |
measure("original") { original } | |
measure("fixed") { fixed_with_split } | |
measure("fixed_without_split") { fixed_without_split } | |
measure("fixed_without_loop") { fixed_without_loop } | |
measure("fixed_using_index") { fixed_using_index } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment