Skip to content

Commit 586aa14

Browse files
committed
Lower case normalization benchmark.
1 parent 2c492d3 commit 586aa14

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
require 'benchmark/ips'
2+
3+
class NormalizedHeaders
4+
def initialize(fields)
5+
@fields = fields
6+
end
7+
8+
def [](key)
9+
@fields[key.downcase]
10+
end
11+
end
12+
13+
class Headers
14+
def initialize(fields)
15+
@fields = fields
16+
end
17+
18+
def [](key)
19+
@fields[key]
20+
end
21+
end
22+
23+
FIELDS = {
24+
'content-type' => 'text/html',
25+
'content-length' => '127889',
26+
'accept-ranges' => 'bytes',
27+
'date' => 'Tue, 14 Jul 2015 22:00:02 GMT',
28+
'via' => '1.1 varnish',
29+
'age' => '0',
30+
'connection' => 'keep-alive',
31+
'x-served-by' => 'cache-iad2125-IAD',
32+
}
33+
34+
NORMALIZED_HEADERS = NormalizedHeaders.new(FIELDS)
35+
HEADERS = Headers.new(FIELDS)
36+
37+
Benchmark.ips do |x|
38+
x.report('NormalizedHeaders[Content-Type]') { NORMALIZED_HEADERS['Content-Type'] }
39+
x.report('NormalizedHeaders[content-type]') { NORMALIZED_HEADERS['content-type'] }
40+
x.report('Headers') { HEADERS['content-type'] }
41+
42+
x.compare!
43+
end

0 commit comments

Comments
 (0)