org.openjdk.jmh.runner.options.ChainedOptionsBuilder Java Examples

The following examples show how to use org.openjdk.jmh.runner.options.ChainedOptionsBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BenchmarkRunner.java    From git-client-plugin with MIT License 6 votes vote down vote up
@Test
    public void runJmhBenchmarks() throws Exception {
        ChainedOptionsBuilder options = new OptionsBuilder()
                .mode(Mode.AverageTime) // Performance metric is Average time (ms per operation)
                .warmupIterations(5) // Used to warm JVM before executing benchmark tests
                .measurementIterations(5)
                .timeUnit(TimeUnit.MILLISECONDS)
                .threads(2) // TODO: Increase the number of threads and measure performance
                .forks(2)   // Need to increase more forks to get more observations, increases precision.
                .shouldFailOnError(true) // Will stop forking of JVM as soon as there is a compilation error
                .shouldDoGC(true) // do GC between measurement iterations
                .output("jmh-report.json");
//                .resultFormat(ResultFormatType.JSON) // store the results in a file called jmh-report.json
//                .result("jmh-report.json");

        BenchmarkFinder bf = new BenchmarkFinder(getClass());
        bf.findBenchmarks(options);
        new Runner(options.build()).run();
    }
 
Example #2
Source File: BenchmarkTest.java    From jenkins-test-harness with MIT License 6 votes vote down vote up
@Test
public void testJmhBenchmarks() throws Exception {
    // create directory for JMH reports
    Path path = Paths.get("target/jmh-reports/");
    Files.createDirectories(path);

    // number of iterations is kept to a minimum just to verify that the benchmarks work without spending extra
    // time during builds.
    ChainedOptionsBuilder optionsBuilder =
            new OptionsBuilder()
                    .forks(1)
                    .warmupIterations(0)
                    .measurementIterations(1)
                    .measurementBatchSize(1)
                    .shouldFailOnError(true)
                    .result("target/jmh-reports/jmh-benchmark-report.json")
                    .timeUnit(TimeUnit.MICROSECONDS)
                    .resultFormat(ResultFormatType.JSON);
    new BenchmarkFinder(getClass()).findBenchmarks(optionsBuilder);
    new Runner(optionsBuilder.build()).run();
}
 
Example #3
Source File: CascJmhBenchmarkStateTest.java    From configuration-as-code-plugin with MIT License 6 votes vote down vote up
@Test
public void testJmhBenchmarks() throws Exception {
    // number of iterations is kept to a minimum just to verify that the benchmarks work without spending extra
    // time during builds.
    ChainedOptionsBuilder optionsBuilder =
            new OptionsBuilder()
                    .forks(1)
                    .warmupIterations(0)
                    .measurementBatchSize(1)
                    .measurementIterations(1)
                    .shouldFailOnError(true)
                    .result(reportPath)
                    .timeUnit(TimeUnit.MICROSECONDS)
                    .resultFormat(ResultFormatType.JSON);
    new BenchmarkFinder(getClass()).findBenchmarks(optionsBuilder);
    new Runner(optionsBuilder.build()).run();

    assertTrue(Files.exists(Paths.get(reportPath)));
}
 
Example #4
Source File: ThreadLocalRandomBenchMarkRunner.java    From tutorials with MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        ChainedOptionsBuilder options = new OptionsBuilder().include(ThreadLocalRandomBenchMarker.class.getSimpleName())
            .forks(1)
            .shouldFailOnError(true)
            .shouldDoGC(true)
            .jvmArgs("-server");

        for (Integer i : ImmutableList.of(1, 2, 8, 32)) {
            new Runner(
                    options
                            .threads(i)
                            .build())
                    .run();
        }
    }
 
Example #5
Source File: ChronicleQueueMicrobench.java    From Chronicle-Queue with Apache License 2.0 5 votes vote down vote up
private ChainedOptionsBuilder newOptionsBuilder() {
        String className = getClass().getSimpleName();

        final ChainedOptionsBuilder runnerOptions = new OptionsBuilder()
                .include(".*" + className + ".*")
                .jvmArgs(BASE_JVM_ARGS)
                .jvmArgsAppend(jvmArgs()
                );

        if (getWarmupIterations() > 0) {
            runnerOptions.warmupIterations(getWarmupIterations());
        }

        if (getMeasureIterations() > 0) {
            runnerOptions.measurementIterations(getMeasureIterations());
        }

        if (null != getReportDir()) {
            String filePath = getReportDir() + className + ".json";
            File file = new File(filePath);
            if (file.exists()) {
                file.delete();
            } else {
                file.getParentFile().mkdirs();
//                file.createNewFile();
            }

            runnerOptions.resultFormat(ResultFormatType.JSON);
            runnerOptions.result(filePath);
        }

        return runnerOptions;
    }
 
Example #6
Source File: BigMatrixMultiplicationBenchmarking.java    From tutorials with MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Map<String, String> parameters = parseParameters(args);

    ChainedOptionsBuilder builder = new OptionsBuilder()
      .include(BigMatrixMultiplicationBenchmarking.class.getSimpleName())
      .mode(Mode.AverageTime)
      .forks(forks(parameters))
      .warmupIterations(warmupIterations(parameters))
      .measurementIterations(measurementIterations(parameters))
      .timeUnit(TimeUnit.SECONDS);

    parameters.forEach(builder::param);

    new Runner(builder.build()).run();
}
 
Example #7
Source File: BenchmarkFixedIntArrayOffHeapIdMap.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
    throws Exception {
  ChainedOptionsBuilder opt = new OptionsBuilder().include(BenchmarkFixedIntArrayOffHeapIdMap.class.getSimpleName())
      .warmupTime(TimeValue.seconds(10)).warmupIterations(2).measurementTime(TimeValue.seconds(30))
      .measurementIterations(5).forks(1);

  new Runner(opt.build()).run();
}
 
Example #8
Source File: BenchmarkCombineGroupBy.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
    throws Exception {
  ChainedOptionsBuilder opt =
      new OptionsBuilder().include(BenchmarkCombineGroupBy.class.getSimpleName()).warmupTime(TimeValue.seconds(10))
          .warmupIterations(1).measurementTime(TimeValue.seconds(30)).measurementIterations(3).forks(1);

  new Runner(opt.build()).run();
}
 
Example #9
Source File: BenchmarkQueryEngine.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
    throws Exception {
  ChainedOptionsBuilder opt =
      new OptionsBuilder().include(BenchmarkQueryEngine.class.getSimpleName()).warmupTime(TimeValue.seconds(30))
          .warmupIterations(4).measurementTime(TimeValue.seconds(30)).measurementIterations(20);

  if (ENABLE_PROFILING) {
    opt = opt.addProfiler(StackProfiler.class,
        "excludePackages=true;excludePackageNames=sun.,java.net.,io.netty.,org.apache.zookeeper.,org.eclipse.jetty.;lines=5;period=1;top=20");
  }

  new Runner(opt.build()).run();
}
 
Example #10
Source File: BenchmarkIndexedTable.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
    throws Exception {
  ChainedOptionsBuilder opt =
      new OptionsBuilder().include(BenchmarkIndexedTable.class.getSimpleName()).warmupTime(TimeValue.seconds(10))
          .warmupIterations(1).measurementTime(TimeValue.seconds(30)).measurementIterations(3).forks(1);

  new Runner(opt.build()).run();
}
 
Example #11
Source File: BenchmarkGroovyExpressionEvaluation.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
    throws Exception {
  ChainedOptionsBuilder opt = new OptionsBuilder().include(BenchmarkGroovyExpressionEvaluation.class.getSimpleName())
      .warmupTime(TimeValue.seconds(10)).warmupIterations(1).measurementTime(TimeValue.seconds(30))
      .measurementIterations(3).forks(1);
  new Runner(opt.build()).run();
}
 
Example #12
Source File: BenchmarkDictionary.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
    throws Exception {
  ChainedOptionsBuilder opt =
      new OptionsBuilder().include(BenchmarkDictionary.class.getSimpleName()).warmupTime(TimeValue.seconds(60))
          .warmupIterations(8).measurementTime(TimeValue.seconds(60)).measurementIterations(8).forks(5);

  new Runner(opt.build()).run();
}
 
Example #13
Source File: HdrHistogramPerformanceBenchmark.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  ChainedOptionsBuilder opt = new OptionsBuilder()
      .include(HdrHistogramPerformanceBenchmark.class.getSimpleName())
      .warmupIterations(3)
      .measurementIterations(10);
  new Runner(opt.build()).run();
}
 
Example #14
Source File: AbstractBenchmarkBase.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void run() throws Exception {
    final String className = getClass().getSimpleName();

    final ChainedOptionsBuilder runnerOptions = new OptionsBuilder()
            .include(".*" + className + ".*")
            .jvmArgs(getJvmArgs());

    if (getWarmupIterations() > 0) {
        runnerOptions.warmupIterations(getWarmupIterations());
    }

    if (getMeasureIterations() > 0) {
        runnerOptions.measurementIterations(getMeasureIterations());
    }

    if (getForks() > 0) {
        runnerOptions.forks(getForks());
    }

    if (getReportDir() != null) {
        final String dtmStr = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
        final String filePath = getReportDir() + className + "-" + dtmStr + ".json";
        final File file = new File(filePath);
        if (file.exists()) {
            file.delete();
        } else {
            file.getParentFile().mkdirs();
            file.createNewFile();
        }

        runnerOptions.resultFormat(ResultFormatType.JSON);
        runnerOptions.result(filePath);
    }

    new Runner(runnerOptions.build()).run();
}
 
Example #15
Source File: AbstractMicrobenchmarkBase.java    From hpack with Apache License 2.0 5 votes vote down vote up
protected ChainedOptionsBuilder newOptionsBuilder() throws Exception {
    String className = getClass().getSimpleName();

    ChainedOptionsBuilder runnerOptions = new OptionsBuilder()
            .include(".*" + className + ".*")
            .jvmArgs(jvmArgs());

    if (getWarmupIterations() > 0) {
        runnerOptions.warmupIterations(getWarmupIterations());
    }

    if (getMeasureIterations() > 0) {
        runnerOptions.measurementIterations(getMeasureIterations());
    }

    if (getForks() > 0) {
        runnerOptions.forks(getForks());
    }

    if (getReportDir() != null) {
        String filePath = getReportDir() + className + ".json";
        File file = new File(filePath);
        if (file.exists()) {
            file.delete();
        } else {
            file.getParentFile().mkdirs();
            file.createNewFile();
        }

        runnerOptions.resultFormat(ResultFormatType.JSON);
        runnerOptions.result(filePath);
    }

    return runnerOptions;
}
 
Example #16
Source File: JmhWaitStategyBenchmark.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Benchmark runner
 */
public static void main(String[] args) throws RunnerException {
    List<String> policies = Arrays.asList("inc", "dec", "r25", "r50", "r75");
    int[] threads = {2, 4, 8, 16, 32};

    List<RunResult> results = new ArrayList<>();

    for (String policy : policies) {
        for (int thread : threads) {
            ChainedOptionsBuilder builder = new OptionsBuilder()
                .jvmArgs()
                .timeUnit(TimeUnit.MILLISECONDS)
                .measurementIterations(10)
                .measurementTime(TimeValue.seconds(20))
                .warmupIterations(5)
                .warmupTime(TimeValue.seconds(10))
                .jvmArgs("-Dbench.exp.policy=" + policy)
                .forks(1)
                .threads(thread)
                .mode(Mode.Throughput)
                .include(JmhWaitStategyBenchmark.class.getSimpleName());

            results.addAll(new Runner(builder.build()).run());
        }
    }

    for (RunResult result : results) {
        BenchmarkParams params = result.getParams();
        Collection<String> args1 = params.getJvmArgs();
        for (String s : args1) {
            System.out.print(s.substring(s.length() - 3, s.length()));
            System.out.print(" x ");
        }
        System.out.print(params.getThreads());
        System.out.print("\t\t");
        System.out.println(result.getPrimaryResult().toString());
    }
}
 
Example #17
Source File: Benchmarks.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) throws RunnerException, CommandLineOptionException {

		CommandLineOptions commandLineOptions = new CommandLineOptions(args);
		ChainedOptionsBuilder builder = new OptionsBuilder().parent(commandLineOptions)
			.include(Benchmarks.class.getSimpleName())
			.jvmArgsAppend("-ea");

		new Runner(builder.build()).run();
	}
 
Example #18
Source File: AbstractMicrobenchmark.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Test
public void run() throws Exception {
    String className = getClass().getSimpleName();

    ChainedOptionsBuilder runnerOptions = new OptionsBuilder()
        .include(".*" + className + ".*")
        .jvmArgs(JVM_ARGS);

    if (getWarmupIterations() > 0) {
        runnerOptions.warmupIterations(getWarmupIterations());
    }

    if (getMeasureIterations() > 0) {
        runnerOptions.measurementIterations(getMeasureIterations());
    }

    if (getForks() > 0) {
        runnerOptions.forks(getForks());
    }

    if (getReportDir() != null) {
        String filePath = getReportDir() + className + ".json";
        File file = new File(filePath);
        if (file.exists()) {
            file.delete();
        } else {
            file.getParentFile().mkdirs();
            file.createNewFile();
        }

        runnerOptions.resultFormat(ResultFormatType.JSON);
        runnerOptions.result(filePath);
    }

    new Runner(runnerOptions.build()).run();
}
 
Example #19
Source File: Client.java    From dubbo-benchmark with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.out.println(args);
    org.apache.commons.cli.Options options = new org.apache.commons.cli.Options();

    options.addOption(Option.builder().longOpt("warmupIterations").hasArg().build());
    options.addOption(Option.builder().longOpt("warmupTime").hasArg().build());
    options.addOption(Option.builder().longOpt("measurementIterations").hasArg().build());
    options.addOption(Option.builder().longOpt("measurementTime").hasArg().build());

    CommandLineParser parser = new DefaultParser();

    CommandLine line = parser.parse(options, args);

    int warmupIterations = Integer.valueOf(line.getOptionValue("warmupIterations", "3"));
    int warmupTime = Integer.valueOf(line.getOptionValue("warmupTime", "10"));
    int measurementIterations = Integer.valueOf(line.getOptionValue("measurementIterations", "3"));
    int measurementTime = Integer.valueOf(line.getOptionValue("measurementTime", "10"));

    Options opt;
    ChainedOptionsBuilder optBuilder = new OptionsBuilder()
            .include(Client.class.getSimpleName())
            .warmupIterations(warmupIterations)
            .warmupTime(TimeValue.seconds(warmupTime))
            .measurementIterations(measurementIterations)
            .measurementTime(TimeValue.seconds(measurementTime))
            .threads(CONCURRENCY)
            .forks(1);

    opt = doOptions(optBuilder).build();

    new Runner(opt).run();

}
 
Example #20
Source File: Benchmarks.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) throws RunnerException, CommandLineOptionException {

		CommandLineOptions commandLineOptions = new CommandLineOptions(args);
		ChainedOptionsBuilder builder = new OptionsBuilder().parent(commandLineOptions)
			.include(Benchmarks.class.getSimpleName())
			.jvmArgsAppend("-ea");

		new Runner(builder.build()).run();
	}
 
Example #21
Source File: Benchmarks.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) throws RunnerException, CommandLineOptionException {

		CommandLineOptions commandLineOptions = new CommandLineOptions(args);
		ChainedOptionsBuilder builder = new OptionsBuilder().parent(commandLineOptions)
			.include(Benchmarks.class.getSimpleName())
			.jvmArgsAppend("-ea");

		new Runner(builder.build()).run();
	}
 
Example #22
Source File: Benchmarks.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) throws RunnerException, CommandLineOptionException {

		CommandLineOptions commandLineOptions = new CommandLineOptions(args);
		ChainedOptionsBuilder builder = new OptionsBuilder().parent(commandLineOptions)
			.include(Benchmarks.class.getSimpleName())
			.jvmArgsAppend("-ea");

		new Runner(builder.build()).run();
	}
 
Example #23
Source File: BenchmarkRunner.java    From folder-auth-plugin with MIT License 5 votes vote down vote up
@Test
public void runBenchmarks() throws IOException, RunnerException {
    ChainedOptionsBuilder options = new OptionsBuilder()
                                        .forks(2)
                                        .mode(Mode.AverageTime)
                                        .shouldDoGC(true)
                                        .shouldFailOnError(true)
                                        .result("jmh-report.json")
                                        .resultFormat(ResultFormatType.JSON)
                                        .timeUnit(TimeUnit.MICROSECONDS)
                                        .threads(2);

    new BenchmarkFinder(BenchmarkRunner.class).findBenchmarks(options);
    new Runner(options.build()).run();
}
 
Example #24
Source File: EscapeCsvBenchmark.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
protected ChainedOptionsBuilder newOptionsBuilder() throws Exception {
    return super.newOptionsBuilder()
                .param("value", "netty")
                .param("value", "\"123\"", "need\"escape", "need,quotes", "  trim-me  ", "short-comma-ended,")
                .param("value", value1024)
                .param("value", value1024commaAtEnd);
}
 
Example #25
Source File: AbstractMicrobenchmark.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
protected ChainedOptionsBuilder newOptionsBuilder() throws Exception {
    ChainedOptionsBuilder runnerOptions = super.newOptionsBuilder();
    if (getForks() > 0) {
        runnerOptions.forks(getForks());
    }

    return runnerOptions;
}
 
Example #26
Source File: AbstractMicrobenchmarkBase.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
protected ChainedOptionsBuilder newOptionsBuilder() throws Exception {
    String className = getClass().getSimpleName();

    ChainedOptionsBuilder runnerOptions = new OptionsBuilder()
        .include(".*" + className + ".*")
        .jvmArgs(jvmArgs());

    if (getWarmupIterations() > 0) {
        runnerOptions.warmupIterations(getWarmupIterations());
    }

    if (getMeasureIterations() > 0) {
        runnerOptions.measurementIterations(getMeasureIterations());
    }

    if (getReportDir() != null) {
        String filePath = getReportDir() + className + ".json";
        File file = new File(filePath);
        if (file.exists()) {
            file.delete();
        } else {
            file.getParentFile().mkdirs();
            file.createNewFile();
        }

        runnerOptions.resultFormat(ResultFormatType.JSON);
        runnerOptions.result(filePath);
    }

    return runnerOptions;
}
 
Example #27
Source File: BenchmarkFinder.java    From jenkins-test-harness with MIT License 5 votes vote down vote up
/**
 * Includes classes annotated with {@link JmhBenchmark} as candidates for JMH benchmarks.
 *
 * @param optionsBuilder the optionsBuilder used to build the benchmarks
 */
public void findBenchmarks(ChainedOptionsBuilder optionsBuilder) throws IOException {
    for (AnnotatedElement e : Index.list(JmhBenchmark.class, classLoader)) {
        Class<?> clazz = (Class<?>) e;
        JmhBenchmark annotation = clazz.getAnnotation(JmhBenchmark.class);
        optionsBuilder.include(clazz.getName() + annotation.value());
    }
}
 
Example #28
Source File: Client.java    From dubbo-benchmark with Apache License 2.0 5 votes vote down vote up
private static ChainedOptionsBuilder doOptions(ChainedOptionsBuilder optBuilder) {
    String output = System.getProperty("benchmark.output");
    if (output != null && !output.trim().isEmpty()) {
        optBuilder.output(output);
    }
    return optBuilder;
}
 
Example #29
Source File: ClientPb.java    From dubbo-benchmark with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Options opt;
    ChainedOptionsBuilder optBuilder = new OptionsBuilder()
            .include(ClientPb.class.getSimpleName())
            .warmupIterations(3)
            .warmupTime(TimeValue.seconds(10))
            .measurementIterations(3)
            .measurementTime(TimeValue.seconds(10))
            .threads(CONCURRENCY)
            .forks(1);

    opt = doOptions(optBuilder).build();

    new Runner(opt).run();
}
 
Example #30
Source File: ClientPb.java    From dubbo-benchmark with Apache License 2.0 5 votes vote down vote up
private static ChainedOptionsBuilder doOptions(ChainedOptionsBuilder optBuilder) {
    String output = System.getProperty("benchmark.output");
    if (output != null && !output.trim().isEmpty()) {
        optBuilder.output(output);
    }
    return optBuilder;
}