JMH: Returning the benchmark results as a json object
Asked Answered
G

1

8

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?

Gentle answered 6/2, 2017 at 15:47 Comment(0)
M
16

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
Micromillimeter answered 19/9, 2017 at 11:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.