1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty5.handler.codec.http;
17
18 import io.netty5.microbench.util.AbstractMicrobenchmark;
19 import org.openjdk.jmh.annotations.Benchmark;
20 import org.openjdk.jmh.annotations.Measurement;
21 import org.openjdk.jmh.annotations.OutputTimeUnit;
22 import org.openjdk.jmh.annotations.Threads;
23 import org.openjdk.jmh.annotations.Warmup;
24
25 import java.nio.charset.Charset;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.concurrent.TimeUnit;
29
30 @Threads(1)
31 @Warmup(iterations = 3)
32 @Measurement(iterations = 3)
33 @OutputTimeUnit(TimeUnit.MICROSECONDS)
34 public class QueryStringDecoderBenchmark extends AbstractMicrobenchmark {
35
36 private static final Charset SHIFT_JIS = Charset.forName("Shift-JIS");
37
38 @Benchmark
39 public Map<String, List<String>> noDecoding() {
40 return new QueryStringDecoder("foo=bar&cat=dog", false).parameters();
41 }
42
43 @Benchmark
44 public Map<String, List<String>> onlyDecoding() {
45
46 return new QueryStringDecoder("%E3%81%BB%E3%81%92=%E3%81%BC%E3%81%91&%E3%81%AD%E3%81%93=%E3%81%84%E3%81%AC",
47 false)
48 .parameters();
49 }
50
51 @Benchmark
52 public Map<String, List<String>> mixedDecoding() {
53
54 return new QueryStringDecoder("foo=bar%E3%81%BB%E3%81%92=%E3%81%BC%E3%81%91&cat=dog&" +
55 "&%E3%81%AD%E3%81%93=%E3%81%84%E3%81%AC", false)
56 .parameters();
57 }
58
59 @Benchmark
60 public Map<String, List<String>> nonStandardDecoding() {
61
62 return new QueryStringDecoder("%82%D9%82%B0=%82%DA%82%AF&%82%CB%82%B1=%82%A2%82%CA",
63 SHIFT_JIS, false)
64 .parameters();
65 }
66 }