|
| 1 | +/* |
| 2 | + * (c) Copyright 2019 Palantir Technologies Inc. All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://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, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.palantir.sls.versions; |
| 18 | + |
| 19 | +import java.util.concurrent.TimeUnit; |
| 20 | +import org.openjdk.jmh.annotations.Benchmark; |
| 21 | +import org.openjdk.jmh.annotations.BenchmarkMode; |
| 22 | +import org.openjdk.jmh.annotations.Fork; |
| 23 | +import org.openjdk.jmh.annotations.Measurement; |
| 24 | +import org.openjdk.jmh.annotations.Mode; |
| 25 | +import org.openjdk.jmh.annotations.OutputTimeUnit; |
| 26 | +import org.openjdk.jmh.annotations.Param; |
| 27 | +import org.openjdk.jmh.annotations.Scope; |
| 28 | +import org.openjdk.jmh.annotations.State; |
| 29 | +import org.openjdk.jmh.annotations.Threads; |
| 30 | +import org.openjdk.jmh.annotations.Warmup; |
| 31 | +import org.openjdk.jmh.profile.GCProfiler; |
| 32 | +import org.openjdk.jmh.runner.Runner; |
| 33 | +import org.openjdk.jmh.runner.options.Options; |
| 34 | +import org.openjdk.jmh.runner.options.OptionsBuilder; |
| 35 | +import org.openjdk.jmh.runner.options.TimeValue; |
| 36 | + |
| 37 | +@State(Scope.Benchmark) |
| 38 | +@BenchmarkMode(Mode.AverageTime) |
| 39 | +@OutputTimeUnit(TimeUnit.NANOSECONDS) |
| 40 | +@Warmup(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS) |
| 41 | +@Measurement(iterations = 3, time = 3, timeUnit = TimeUnit.SECONDS) |
| 42 | +@Fork(1) |
| 43 | +@Threads(4) |
| 44 | +@SuppressWarnings({ |
| 45 | + "checkstyle:hideutilityclassconstructor", |
| 46 | + "VisibilityModifier", |
| 47 | + "DesignForExtension", |
| 48 | + "ImmutableEnumChecker" |
| 49 | +}) |
| 50 | +public class SlsVersionComparisonBenchmark { |
| 51 | + |
| 52 | + public enum Version { |
| 53 | + RELEASE("0.16.0"), |
| 54 | + SNAPSHOT("0.16.0-8-g116b425"), |
| 55 | + RC("0.16.0-rc1"), |
| 56 | + RC_SNAPSHOT("0.16.0-rc1-8-g116b425"), |
| 57 | + ; |
| 58 | + |
| 59 | + private final OrderableSlsVersion version1; |
| 60 | + // Used to avoid comparing the object's identities when comparing the same version |
| 61 | + private final OrderableSlsVersion version2; |
| 62 | + |
| 63 | + Version(String string) { |
| 64 | + this.version1 = OrderableSlsVersion.valueOf(string); |
| 65 | + this.version2 = OrderableSlsVersion.valueOf(string); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + @Param |
| 70 | + Version version1; |
| 71 | + |
| 72 | + @Param |
| 73 | + Version version2; |
| 74 | + |
| 75 | + @Benchmark |
| 76 | + public int compare() { |
| 77 | + return version1.version1.compareTo(version2.version2); |
| 78 | + } |
| 79 | + |
| 80 | + public static void main(String[] _args) throws Exception { |
| 81 | + Options opt = new OptionsBuilder() |
| 82 | + .include(SlsVersionComparisonBenchmark.class.getSimpleName()) |
| 83 | + .addProfiler(GCProfiler.class) |
| 84 | + .forks(1) |
| 85 | + .threads(4) |
| 86 | + .warmupIterations(3) |
| 87 | + .warmupTime(TimeValue.seconds(3)) |
| 88 | + .measurementIterations(3) |
| 89 | + .measurementTime(TimeValue.seconds(3)) |
| 90 | + .build(); |
| 91 | + new Runner(opt).run(); |
| 92 | + } |
| 93 | +} |
0 commit comments