|
| 1 | +/** |
| 2 | + * Copyright 2015-2016 The OpenZipkin Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 5 | + * in compliance with the License. You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License |
| 10 | + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 11 | + * or implied. See the License for the specific language governing permissions and limitations under |
| 12 | + * the License. |
| 13 | + */ |
| 14 | +package brave.jersey.server; |
| 15 | + |
| 16 | +import java.net.URI; |
| 17 | +import java.util.Arrays; |
| 18 | +import java.util.concurrent.TimeUnit; |
| 19 | +import org.glassfish.jersey.internal.MapPropertiesDelegate; |
| 20 | +import org.glassfish.jersey.server.ContainerRequest; |
| 21 | +import org.glassfish.jersey.server.ContainerResponse; |
| 22 | +import org.glassfish.jersey.server.ExtendedUriInfo; |
| 23 | +import org.glassfish.jersey.uri.PathTemplate; |
| 24 | +import org.jboss.resteasy.core.ServerResponse; |
| 25 | +import org.openjdk.jmh.annotations.Benchmark; |
| 26 | +import org.openjdk.jmh.annotations.BenchmarkMode; |
| 27 | +import org.openjdk.jmh.annotations.Fork; |
| 28 | +import org.openjdk.jmh.annotations.Measurement; |
| 29 | +import org.openjdk.jmh.annotations.Mode; |
| 30 | +import org.openjdk.jmh.annotations.OutputTimeUnit; |
| 31 | +import org.openjdk.jmh.annotations.Scope; |
| 32 | +import org.openjdk.jmh.annotations.State; |
| 33 | +import org.openjdk.jmh.annotations.Warmup; |
| 34 | +import org.openjdk.jmh.runner.Runner; |
| 35 | +import org.openjdk.jmh.runner.RunnerException; |
| 36 | +import org.openjdk.jmh.runner.options.Options; |
| 37 | +import org.openjdk.jmh.runner.options.OptionsBuilder; |
| 38 | + |
| 39 | +@Measurement(iterations = 5, time = 1) |
| 40 | +@Warmup(iterations = 10, time = 1) |
| 41 | +@Fork(3) |
| 42 | +@BenchmarkMode(Mode.Throughput) |
| 43 | +@OutputTimeUnit(TimeUnit.MICROSECONDS) |
| 44 | +@State(Scope.Thread) |
| 45 | +public class TracingApplicationEventListenerAdapterBenchmarks { |
| 46 | + FakeExtendedUriInfo uriInfo = new FakeExtendedUriInfo(URI.create("/"), |
| 47 | + Arrays.asList( |
| 48 | + new PathTemplate("/"), |
| 49 | + new PathTemplate("/items/{itemId}"), |
| 50 | + new PathTemplate("/"), |
| 51 | + new PathTemplate("/nested") |
| 52 | + ) |
| 53 | + ); |
| 54 | + ContainerResponse response = new ContainerResponse( |
| 55 | + new ContainerRequest( |
| 56 | + URI.create("/"), null, null, null, new MapPropertiesDelegate() |
| 57 | + ) { |
| 58 | + @Override public ExtendedUriInfo getUriInfo() { |
| 59 | + return uriInfo; |
| 60 | + } |
| 61 | + }, new ServerResponse()); |
| 62 | + |
| 63 | + TracingApplicationEventListener.Adapter adapter = new TracingApplicationEventListener.Adapter(); |
| 64 | + |
| 65 | + @Benchmark public String parseRoute() { |
| 66 | + return adapter.route(response); |
| 67 | + } |
| 68 | + |
| 69 | + // Convenience main entry-point |
| 70 | + public static void main(String[] args) throws RunnerException { |
| 71 | + Options opt = new OptionsBuilder() |
| 72 | + .include(".*" + TracingApplicationEventListenerAdapterBenchmarks.class.getSimpleName()) |
| 73 | + .build(); |
| 74 | + |
| 75 | + new Runner(opt).run(); |
| 76 | + } |
| 77 | +} |
0 commit comments