java - dynamic annotation for junitbenchmark -


I write some junior benchmark tests on time. Now I want to set up warm-up and test rounds from the wrapper class. How to set benchmark option annotations from cover?

My wrapper class:

  import org.junit.runner.JUnitCore; Import org.junit.runner.Result; Public class wrapper {public static zero main (string [] args) {junitak junior = new jyentitcore (); Result result; Results = Junior.Ren (test class); }}  

My test method in Test.class:

  @BenchmarkOptions (benchmarked = 50, warmupRounds = 10) @Test Public Zero test1 () {// do something}  

Previous Your code does not work

  1. You are missing benchmark rules in your trial.
  2. You can not name a class test on importing an annotation named test . It will not compile.

So I name that class as benchmark test .


To return to your question, you can use the Benchmark Option System Properties Its documentation has been written in.

Global settings for standard set through system properties If IGNORE_ANNOTATION_OPTIONS_PROPERTY is specified, then system priority and default method- and class-level annotations will take precedence.

This allows you to write a wrapper

  import org.junit.runner.JUnitCore; Import org.junit.runner.Result; Import com.carrotsearch.junitbenchmarks.BenchmarkOptionsSystemProperties; Public class wrapper {public static zero main (string [] args) {System.setProperty (benchmark opprimation system properties .IGNORE_ANNOTATION_OPTIONS_PROPERTY, "true"); System.setProperty (BenchmarkOptionsSystemProperties.WARMUP_ROUNDS_PROPERTY, "20"); System.setProperty (BenchmarkOptionsSystemProperties.BENCHMARK_ROUNDS_PROPERTY, "20"); Junitak junit = new giantitcore (); Results Result = Jr.Ren (BenchmarkTest.class); }}  

According to the benchmark will look like this

  import org.junit.Rule; Import org.junit.Test; Import org.junit.rules.TestRule; Import com.carrotsearch.junitbenchmarks.BenchmarkOptions; Import com.carrotsearch.junitbenchmarks.BenchmarkOptionsSystemProperties; Import com.carrotsearch.junitbenchmarks.BenchmarkRule; Public Class Benchmark Test {@Royal Public Testerual Benchmark Run = New Benchmark Rule (BenchmarkOptions SystemProperties .get Default Consumers ()); @Test @BenchmarkOptions (Benchmarkers = 1, Warm UpRound = 1) Public Zero Test1 () {int tmp = 1 + 2; }}  

When you execute the Mapper-Mode then you receive this output, where you can see that the annotation values ​​of 1 are overridden.

BenchmarkTest.test1: [20 rounds of 40, threads: 1 (sequential) round: 0.00 [+ - 0.00], round. Block: 0.00 [+ - 0.00], Round-GC : 0.00 [+ - 0.00], G.C. Coles: 0, GC. Time: 0.00, TimeTotal: 0.01, Time. Warmup: 0.00, Time. Base: 0.00


Comments