1 /* 2 * Copyright 2021 Carl Mastrangelo 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 io.perfmark.java9; 18 19 import io.perfmark.impl.Generator; 20 import io.perfmark.testing.GarbageCollector; 21 import io.perfmark.testing.GeneratorBenchmark; 22 import java.util.concurrent.TimeUnit; 23 import org.junit.Test; 24 import org.junit.runner.RunWith; 25 import org.junit.runners.JUnit4; 26 import org.openjdk.jmh.annotations.Benchmark; 27 import org.openjdk.jmh.annotations.BenchmarkMode; 28 import org.openjdk.jmh.annotations.GroupThreads; 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.runner.Runner; 34 import org.openjdk.jmh.runner.options.Options; 35 import org.openjdk.jmh.runner.options.OptionsBuilder; 36 import org.openjdk.jmh.runner.options.TimeValue; 37 import org.openjdk.jmh.runner.options.VerboseMode; 38 39 @RunWith(JUnit4.class) 40 public class VarHandleGeneratorBenchmarkTest { 41 42 @Test generatorBenchmark()43 public void generatorBenchmark() throws Exception { 44 Options options = new OptionsBuilder() 45 .include(VarHandleGeneratorBenchmark.class.getCanonicalName()) 46 .measurementIterations(5) 47 .warmupIterations(10) 48 .forks(1) 49 .verbosity(VerboseMode.EXTRA) 50 .warmupTime(TimeValue.seconds(1)) 51 .measurementTime(TimeValue.seconds(1)) 52 .shouldFailOnError(true) 53 // This is necessary to run in the IDE, otherwise it would inherit the VM args. 54 .jvmArgs("-da") 55 .build(); 56 57 new Runner(options).run(); 58 } 59 60 @State(Scope.Benchmark) 61 public static class VarHandleGeneratorBenchmark extends GeneratorBenchmark { 62 @Override getGenerator()63 protected Generator getGenerator() { 64 return new SecretVarHandleGenerator.VarHandleGenerator(); 65 } 66 } 67 } 68