Created
March 8, 2015 08:10
-
-
Save Lukasa/1b83c2c1e947bed0da9b to your computer and use it in GitHub Desktop.
Profiles various header mappings.
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
import time | |
from hyper.common.headers import HTTPHeaderMap | |
from urllib3._collections import HTTPHeaderDict | |
def timeit(method): | |
def timed(*args, **kw): | |
ts = time.clock() | |
for _ in range(10000): | |
result = method(*args, **kw) | |
te = time.clock() | |
print('%r (%r, %r) %2.2f sec' % \ | |
(method.__name__, args, kw, te-ts)) | |
return result | |
return timed | |
headers = [ | |
("content-length", "14684"), | |
("x-content-type-options", "nosniff"), | |
("content-encoding", "gzip"), | |
("expires", "Tue, 29 Oct 2013 02:44:39 GMT"), | |
("vary", "Accept-Encoding"), | |
("last-modified", "Sun, 28 Oct 2012 21:37:35 GMT"), | |
("connection", "keep-alive"), | |
("cache-control", "public, max-age=31067635"), | |
("date", "Sat, 03 Nov 2012 12:50:44 GMT"), | |
("access-control-allow-origin", "*"), | |
("content-type", "text/css; charset=utf-8"), | |
("x-fb-debug", "Qc0GcUiwi3io8aSRIdXaahYr6KKhphvV6NlN8vo/bD4="), | |
] | |
@timeit | |
def test_creation(header_map): | |
hmap = header_map(headers) | |
assert hmap['access-control-allow-origin'] | |
@timeit | |
def test_access(hmap): | |
assert hmap['access-control-allow-origin'] | |
test_creation(HTTPHeaderMap) | |
test_creation(HTTPHeaderDict) | |
test_creation(dict) | |
hmap1 = HTTPHeaderMap(headers) | |
hmap2 = HTTPHeaderDict(headers) | |
hmap3 = dict(headers) | |
test_access(hmap1) | |
test_access(hmap2) | |
test_access(hmap3) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment