Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit e6ca2a3

Browse files
schlosnapavelbucek
authored andcommitted
Add JMH benchmark for JerseyUriBuilder parsing
Change-Id: I05dec2875b2a9b6830b6b9d4b604a3c267889e09
1 parent b61b474 commit e6ca2a3

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

tests/performance/benchmarks/src/main/java/org/glassfish/jersey/tests/performance/benchmark/AllBenchmarks.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2015-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -59,6 +59,7 @@ public static void main(final String[] args) throws Exception {
5959
.include(ClientBenchmark.class.getSimpleName())
6060
.include(JacksonBenchmark.class.getSimpleName())
6161
.include(LocatorBenchmark.class.getSimpleName())
62+
.include(JerseyUriBuilderBenchmark.class.getSimpleName())
6263
// Measure throughput in seconds (ops/s).
6364
.mode(Mode.Throughput)
6465
.timeUnit(TimeUnit.SECONDS)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
41+
package org.glassfish.jersey.tests.performance.benchmark;
42+
43+
import java.util.concurrent.TimeUnit;
44+
45+
import org.glassfish.jersey.uri.internal.JerseyUriBuilder;
46+
47+
import org.openjdk.jmh.annotations.Benchmark;
48+
import org.openjdk.jmh.annotations.BenchmarkMode;
49+
import org.openjdk.jmh.annotations.Fork;
50+
import org.openjdk.jmh.annotations.Measurement;
51+
import org.openjdk.jmh.annotations.Mode;
52+
import org.openjdk.jmh.annotations.OutputTimeUnit;
53+
import org.openjdk.jmh.annotations.Param;
54+
import org.openjdk.jmh.annotations.Scope;
55+
import org.openjdk.jmh.annotations.Setup;
56+
import org.openjdk.jmh.annotations.State;
57+
import org.openjdk.jmh.annotations.Warmup;
58+
import org.openjdk.jmh.runner.Runner;
59+
import org.openjdk.jmh.runner.options.Options;
60+
import org.openjdk.jmh.runner.options.OptionsBuilder;
61+
62+
/**
63+
* {@link JerseyUriBuilder} benchmark for parsing templates.
64+
*
65+
* @author David Schlosnagle
66+
*/
67+
@BenchmarkMode(Mode.Throughput)
68+
@OutputTimeUnit(TimeUnit.SECONDS)
69+
@Warmup(iterations = 16, time = 2500, timeUnit = TimeUnit.MILLISECONDS)
70+
@Measurement(iterations = 16, time = 2500, timeUnit = TimeUnit.MILLISECONDS)
71+
@Fork(1)
72+
@State(Scope.Benchmark)
73+
public class JerseyUriBuilderBenchmark {
74+
75+
@Param(value = {"http://localhost:8080/a/b/c", "https://localhost:443/{a}/{b}/{c:.+}"})
76+
private String uriTemplate;
77+
78+
private volatile JerseyUriBuilder uriBuilder;
79+
80+
@Setup
81+
public void start() throws Exception {
82+
uriBuilder = new JerseyUriBuilder();
83+
}
84+
85+
@Benchmark
86+
public JerseyUriBuilder uri() throws Exception {
87+
return uriBuilder.uri(uriTemplate);
88+
}
89+
90+
public static void main(final String[] args) throws Exception {
91+
final Options opt = new OptionsBuilder()
92+
// Register our benchmarks.
93+
.include(JerseyUriBuilderBenchmark.class.getSimpleName())
94+
.build();
95+
96+
new Runner(opt).run();
97+
}
98+
}

0 commit comments

Comments
 (0)