Wednesday 3 August 2022

JMH: result format types

At the time of writing this post, JMH support following result format types.

 

a.   TEXT

b.   CSV

c.    SCSV

d.   JSON

e.   LATEX

 

For example, below snippet set the result format type to JSON.

 Options opt = new OptionsBuilder()
.include(OptionsBuilderDemo.class.getSimpleName())
.forks(1)
.measurementIterations(4)
.warmupIterations(3)
.resultFormat(ResultFormatType.JSON)
.result("/Users/Shared/result.json")
.build();

 

Find the below working application.

 


ResultFormatTypes.java
package com.sample.app;

import java.util.concurrent.TimeUnit;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

public class ResultFormatTypes {
	
	@Benchmark
	public void test1() throws InterruptedException {
		TimeUnit.MILLISECONDS.sleep(300);
	}
	
	public static void main(String[] args) throws RunnerException {
		Options opt = new OptionsBuilder()
				.include(OptionsBuilderDemo.class.getSimpleName())
				.forks(1)
				.measurementIterations(4)
				.warmupIterations(3)
				.resultFormat(ResultFormatType.JSON)
				.result("/Users/Shared/result.json")
				.build();

		new Runner(opt).run();
	}
}

Run the application and you can see result.json file will be created with benchmark results.

 

result.json

[
    {
        "jmhVersion" : "1.35",
        "benchmark" : "com.sample.app.OptionsBuilderDemo.randString",
        "mode" : "thrpt",
        "threads" : 1,
        "forks" : 1,
        "jvm" : "/Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home/bin/java",
        "jvmArgs" : [
            "-Dfile.encoding=UTF-8",
            "-XX:+ShowCodeDetailsInExceptionMessages"
        ],
        "jdkVersion" : "15.0.2",
        "vmName" : "Java HotSpot(TM) 64-Bit Server VM",
        "vmVersion" : "15.0.2+7-27",
        "warmupIterations" : 3,
        "warmupTime" : "10 s",
        "warmupBatchSize" : 1,
        "measurementIterations" : 4,
        "measurementTime" : "10 s",
        "measurementBatchSize" : 1,
        "primaryMetric" : {
            "score" : 89.14587141327391,
            "scoreError" : 4.071006493877836,
            "scoreConfidence" : [
                85.07486491939608,
                93.21687790715174
            ],
            "scorePercentiles" : {
                "0.0" : 88.43890338977174,
                "50.0" : 89.0898802448304,
                "90.0" : 89.96482177366312,
                "95.0" : 89.96482177366312,
                "99.0" : 89.96482177366312,
                "99.9" : 89.96482177366312,
                "99.99" : 89.96482177366312,
                "99.999" : 89.96482177366312,
                "99.9999" : 89.96482177366312,
                "100.0" : 89.96482177366312
            },
            "scoreUnit" : "ops/s",
            "rawData" : [
                [
                    89.96482177366312,
                    89.17330427249975,
                    89.00645621716103,
                    88.43890338977174
                ]
            ]
        },
        "secondaryMetrics" : {
        }
    }
]

 

Previous                                                 Next                                                 Home

No comments:

Post a Comment