From dbe29c1c4b3c1616de0bec57948cdbc1a3a47780 Mon Sep 17 00:00:00 2001 From: Wenshuai Hou Date: Fri, 14 Jun 2019 12:56:24 -0400 Subject: [PATCH 1/2] update jmh tests - add to testImplementation - blackhole consume to avoid code elimination --- tracing-undertow/build.gradle | 3 ++ .../tracing/undertow/TracingBenchMark.java | 50 +++++++++++++++++++ versions.props | 1 + 3 files changed, 54 insertions(+) create mode 100644 tracing-undertow/src/test/java/com/palantir/tracing/undertow/TracingBenchMark.java diff --git a/tracing-undertow/build.gradle b/tracing-undertow/build.gradle index 1abcadca5..3bdc69c80 100644 --- a/tracing-undertow/build.gradle +++ b/tracing-undertow/build.gradle @@ -23,6 +23,9 @@ dependencies { implementation project(':tracing-api') implementation 'com.google.guava:guava' implementation 'com.palantir.safe-logging:preconditions' + testImplementation 'org.openjdk.jmh:jmh-core' + testImplementation 'org.openjdk.jmh:jmh-generator-annprocess' + annotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess' // Required for tests using the slf4j MDC which is not implemented in slf4j-simple testImplementation 'ch.qos.logback:logback-classic' diff --git a/tracing-undertow/src/test/java/com/palantir/tracing/undertow/TracingBenchMark.java b/tracing-undertow/src/test/java/com/palantir/tracing/undertow/TracingBenchMark.java new file mode 100644 index 000000000..3d7a0ede7 --- /dev/null +++ b/tracing-undertow/src/test/java/com/palantir/tracing/undertow/TracingBenchMark.java @@ -0,0 +1,50 @@ +/* + * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.palantir.tracing.undertow; + +import com.palantir.tracing.Tracers; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.profile.GCProfiler; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; +import org.openjdk.jmh.runner.options.TimeValue; + +@State(Scope.Thread) +public class TracingBenchMark { + @Benchmark + public void benchmarkRandomId(Blackhole blackhole) { + blackhole.consume(Tracers.randomId()); + } + + public static void main(String[] args) throws Exception { + Options opt = new OptionsBuilder() + .include(TracingBenchMark.class.getSimpleName()) + .addProfiler(GCProfiler.class) + .forks(1) + .threads(Runtime.getRuntime().availableProcessors()) + .warmupIterations(3) + .warmupTime(TimeValue.seconds(3)) + .measurementIterations(3) + .measurementTime(TimeValue.seconds(3)) + .build(); + new Runner(opt).run(); + } +} diff --git a/versions.props b/versions.props index 3b1279640..bbab59658 100644 --- a/versions.props +++ b/versions.props @@ -21,3 +21,4 @@ org.immutables:value = 2.7.5 org.jmock:jmock = 2.12.0 org.mockito:mockito-core = 2.28.2 ch.qos.logback:logback-classic = 1.1.7 +org.openjdk.jmh:* = 1.21 \ No newline at end of file From 3e09fe1279e906a761ffed04fac08da520da1a33 Mon Sep 17 00:00:00 2001 From: Wenshuai Hou Date: Fri, 14 Jun 2019 13:02:42 -0400 Subject: [PATCH 2/2] checkstyle --- .../java/com/palantir/tracing/undertow/TracingBenchMark.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tracing-undertow/src/test/java/com/palantir/tracing/undertow/TracingBenchMark.java b/tracing-undertow/src/test/java/com/palantir/tracing/undertow/TracingBenchMark.java index 3d7a0ede7..3079561c3 100644 --- a/tracing-undertow/src/test/java/com/palantir/tracing/undertow/TracingBenchMark.java +++ b/tracing-undertow/src/test/java/com/palantir/tracing/undertow/TracingBenchMark.java @@ -30,7 +30,7 @@ @State(Scope.Thread) public class TracingBenchMark { @Benchmark - public void benchmarkRandomId(Blackhole blackhole) { + public final void benchmarkRandomId(Blackhole blackhole) { blackhole.consume(Tracers.randomId()); }