View Javadoc
1   /*
2    * Copyright 2019 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.http;
17  
18  import io.netty.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          // foo=bar&ほげ=ぼけ&cat=dog&ねこ=いぬ
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          // ほげ=ぼけ&ねこ=いぬ in Shift-JIS
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  }