1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| @Slf4j @State(Scope.Benchmark) public class AppApplicationTest {
private final static Integer MEASUREMENT_ITERATIONS = 1; private final static Integer WARMUP_ITERATIONS = 1;
static ConfigurableApplicationContext context;
public String[] activeProfiles;
@Setup(Level.Trial) public synchronized void initialize() { try { String args = ""; if (context == null) { context = SpringApplication.run(AppApplication.class, args); activeProfiles = context.getEnvironment().getActiveProfiles(); } log.info("{}",activeProfiles); } catch (Exception e) { e.printStackTrace(); } }
@Test @Disabled public void executeJmhRunner() throws RunnerException { Options opt = new OptionsBuilder() .include("\\." + AppApplicationTest.class.getSimpleName() + "\\.") .warmupIterations(WARMUP_ITERATIONS) .measurementIterations(MEASUREMENT_ITERATIONS) .timeUnit(TimeUnit.MILLISECONDS) .forks(0) .threads(1) .mode(Mode.AverageTime) .shouldDoGC(true) .shouldFailOnError(true) .resultFormat(ResultFormatType.JSON)
.result("benchmark.json") .shouldFailOnError(true) .jvmArgs("-server") .build(); new Runner(opt).run(); }
@Benchmark public void environment(){
}
}
|