Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMH: Returning the benchmark results as a json object

I am developing an integrated Benchmarking into an application. I want to use JMH as my framework.

How can I receive the results as an JSON object?

I know I can save it in a file with the following running options:

    org.openjdk.jmh.runner.options.Options opt = new OptionsBuilder()
            .include(WorkerBenBenchmarkObject.class.getSimpleName())
            .shouldDoGC(true)
            .resultFormat(ResultFormatType.JSON)
            .result("benchmark-result/" + System.currentTimeMillis() + ".json")
            .addProfiler(StackProfiler.class)
            .jvmArgsAppend("-Djmh.stack.period=1")
            .warmupIterations(5)
            .measurementIterations(5)
            .forks(1)
            .build();

    new Runner(opt).run();

How can I receive this results without needing to read the file?

like image 644
Herget Avatar asked Feb 06 '17 15:02

Herget


People also ask

How do you run JMH benchmarks?

There are two ways to run the JMH benchmark, uses Maven or run it via a JMH Runner class directly. 3.1 Maven, package it as a JAR and run it via org. openjdk.

What is JMH in Java?

JMH is short for Java Microbenchmark Harness. JMH is a toolkit that helps you implement Java microbenchmarks correctly. JMH is developed by the same people who implement the Java virtual machine, so these guys know what they are doing.

How do you benchmark a spring boot application?

The solution was quite than easy than I thought. The important part is to start the spring-boot application when the benchmark is getting initialized. Define a class level variable for configuration context and give a reference to it during setup of the benchmark. Make a call to the bean method inside the benchmark.


1 Answers

If you run JMH from the command line there is an option (-rf) to set the output format.

For JSON output:

java -jar benchmarks.jar -rf json

To get a list of other formats and the options to select:

java -jar benchmarks.jar -lrf
Available formats: text, csv, scsv, json, latex
like image 168
kmt Avatar answered Sep 19 '22 10:09

kmt