File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments