1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.handler.codec.http2;
17
18 import io.netty5.microbench.util.AbstractMicrobenchmark;
19 import io.netty5.util.AsciiString;
20 import io.netty5.util.CharsetUtil;
21 import org.openjdk.jmh.annotations.Benchmark;
22 import org.openjdk.jmh.annotations.BenchmarkMode;
23 import org.openjdk.jmh.annotations.Fork;
24 import org.openjdk.jmh.annotations.Measurement;
25 import org.openjdk.jmh.annotations.Mode;
26 import org.openjdk.jmh.annotations.OutputTimeUnit;
27 import org.openjdk.jmh.annotations.Scope;
28 import org.openjdk.jmh.annotations.State;
29 import org.openjdk.jmh.annotations.Threads;
30 import org.openjdk.jmh.annotations.Warmup;
31
32 import java.util.concurrent.TimeUnit;
33
34 @Fork(1)
35 @Threads(1)
36 @State(Scope.Benchmark)
37 @Warmup(iterations = 5)
38 @Measurement(iterations = 5)
39 @OutputTimeUnit(TimeUnit.NANOSECONDS)
40 public class HpackStaticTableBenchmark extends AbstractMicrobenchmark {
41
42 private static final CharSequence X_CONTENT_ENCODING =
43 new AsciiString("x-content-encoding".getBytes(CharsetUtil.US_ASCII), false);
44 private static final CharSequence X_GZIP = new AsciiString("x-gzip".getBytes(CharsetUtil.US_ASCII), false);
45 private static final CharSequence STATUS = new AsciiString(":status".getBytes(CharsetUtil.US_ASCII), false);
46 private static final CharSequence STATUS_200 = new AsciiString("200".getBytes(CharsetUtil.US_ASCII), false);
47 private static final CharSequence STATUS_500 = new AsciiString("500".getBytes(CharsetUtil.US_ASCII), false);
48 private static final CharSequence AUTHORITY =
49 new AsciiString(":authority".getBytes(CharsetUtil.US_ASCII), false);
50 private static final CharSequence AUTHORITY_NETTY =
51 new AsciiString("netty.io".getBytes(CharsetUtil.US_ASCII), false);
52 private static final CharSequence USER_AGENT =
53 new AsciiString("user-agent".getBytes(CharsetUtil.US_ASCII), false);
54 private static final CharSequence USER_AGENT_CURL =
55 new AsciiString("curl/7.64.1".getBytes(CharsetUtil.US_ASCII), false);
56
57 @Benchmark
58 @BenchmarkMode(Mode.AverageTime)
59 public int lookupNoNameMatch() {
60 return HpackStaticTable.getIndexInsensitive(X_CONTENT_ENCODING, X_GZIP);
61 }
62
63 @Benchmark
64 @BenchmarkMode(Mode.AverageTime)
65 public int lookupNameAndValueMatchFirst() {
66 return HpackStaticTable.getIndexInsensitive(STATUS, STATUS_200);
67 }
68
69 @Benchmark
70 @BenchmarkMode(Mode.AverageTime)
71 public int lookupNameAndValueMatchLast() {
72 return HpackStaticTable.getIndexInsensitive(STATUS, STATUS_500);
73 }
74
75 @Benchmark
76 @BenchmarkMode(Mode.AverageTime)
77 public int lookupNameOnlyMatchBeginTable() {
78 return HpackStaticTable.getIndexInsensitive(AUTHORITY, AUTHORITY_NETTY);
79 }
80
81 @Benchmark
82 @BenchmarkMode(Mode.AverageTime)
83 public int lookupNameOnlyMatchEndTable() {
84 return HpackStaticTable.getIndexInsensitive(USER_AGENT, USER_AGENT_CURL);
85 }
86 }