Last active
August 29, 2015 13:58
-
-
Save smashwilson/10416299 to your computer and use it in GitHub Desktop.
excon case-insensitive header access benchmarks
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
#!/bin/env ruby | |
# | |
# Benchmark any performance degredation associated with moving to case- | |
# insensitive HTTP header access. | |
require 'benchmark' | |
require './lib/excon' | |
resp = Excon::Response.new | |
resp.headers = {} | |
headers = Excon::Headers.new | |
original_headers = [] | |
permuted_headers = [] | |
value = 'irrelevant' | |
File.readlines('headers.txt').each do |header| | |
original_headers << header | |
permuted_headers << header.tr('a-zA-Z', 'A-Za-z') | |
resp.headers[header] = value | |
headers[header] = value | |
end | |
puts "Loaded #{original_headers.size} headers." | |
ITERATIONS = 100_000 | |
Benchmark.bm(35) do |bm| | |
bm.report('hash, with original case:') do | |
ITERATIONS.times do | |
original_headers.each do |header| | |
resp.headers[header] | |
end | |
end | |
end | |
bm.report('hash, with permuted case:') do | |
ITERATIONS.times do | |
permuted_headers.each do |header| | |
# resp.get_header(header) | |
end | |
end | |
end | |
bm.report('Excon::Headers, with original case:') do | |
ITERATIONS.times do | |
original_headers.each do |header| | |
headers[header] | |
end | |
end | |
end | |
bm.report('Excon::Headers, with permuted case:') do | |
ITERATIONS.times do | |
permuted_headers.each do |header| | |
headers[header] | |
end | |
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
x-emc-meta | |
Content-Type | |
location | |
Content-Length | |
ctime | |
date | |
range | |
x-emc-uid | |
x-amz-security-token | |
Authorization | |
X-Amzn-Authorization | |
x-amz-date | |
Host | |
x-amz-glacier-version | |
ETag | |
Transfer-Encoding | |
x-amz-archive-id | |
x-amz-multipart-upload-id | |
x-amz-job-id | |
Last-Modified | |
x-amz-redshift-version | |
If-Match | |
X-Amz-Target | |
x-amz-archive-description | |
x-amz-part-size | |
x-amz-copy-source | |
versionId | |
Content-MD5 | |
x-amz-delete-marker | |
x-amz-version-id | |
If-Modified-Since | |
If-Unmodified-Since | |
Status | |
x-amz-acl | |
X-Amzn-Authorization | |
Accept | |
Cookie | |
User-Agent | |
x-dnsme-apiKey | |
x-dnsme-requestDate | |
x-dnsme-hmac | |
Auth-Token | |
Location | |
x-tmrk-contenthash | |
x-goog-copy-source | |
X-Storage-Url | |
X-Container-Object-Count | |
X-Container-Bytes-Used | |
X-Cdn-Enabled | |
X-Cdn-Uri | |
X-Cdn-Ssl-Uri | |
Accept-Encoding | |
X-Account-Bytes-Used | |
X-Account-Meta-Quota-Bytes | |
X-Image-Meta-Is_public | |
X-Copy-From | |
X-Account-Meta-Temp-Url-Key | |
X-Object-Manifest |
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
Loaded 58 headers. | |
user system total real | |
hash, with original case: 2.020000 0.000000 2.020000 ( 2.024403) | |
hash, with permuted case: 43.810000 0.150000 43.960000 ( 47.884542) | |
Excon::Headers, with original case: 3.520000 0.010000 3.530000 ( 3.587199) | |
Excon::Headers, with permuted case: 6.390000 0.020000 6.410000 ( 6.651364) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment