Use jmh for benchmarks [Was: RFR(s): AArch64: 8149080: Recoginize disjoint array copy in stub code]
Andrew Haley
aph at redhat.com
Wed Feb 10 13:05:26 UTC 2016
It's very important to use JMH for HotSpot benchmarks. Without JMH,
it is very hard to tell if you're measuring the right thing.
In order to help you get started, I've appended a JMH version of your
benchmark. Run it with:
build/linux-aarch64-normal-server-release/jdk/bin/java -jar \
jmh-samples/target/microbenchmarks.jar '.*JMHSample_96.*' -wi 5 -i 10 \
-f 0
Andrew.
-----------------------------------------------------------------------
package org.openjdk.jmh.samples;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.GenerateMicroBenchmark;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
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;
import java.util.concurrent.TimeUnit;
import java.nio.*;
import java.util.*;
import java.util.concurrent.*;
@BenchmarkMode(Mode.AverageTime)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
public class JMHSample_96_StringAppend {
@State(Scope.Benchmark)
public static class BenchmarkState {
final String[] strs = {
"aoiod", // 5
"adsdefrgda", // 10
"dsadsadadsdsadiomjdas", // 20
"djsadusahdusaufdoaaiffjdkdpjikl", // 30
"dsudhusuhfudhaufhduahfduafhdkaffhdjafjdfa", // 40
"dhsuafydagfydagfdafdajlkejwfjfuhfuafjhdahfldjksl90s", // 50
"dsajufhdaufhdasuifhdasjkfndasjkfgbaduygbiafjioeawjfioiopjsdljl", // 60
"dshaudshauidshauidhsiufhdasjklfdbnasjkvbauyvbdyargfwrheuifgeuijikalkjfds", // 70
"nvfjsvnfusdbvfuyafbduyasfdsjkfhdjkasfhdjksafhdjksfhdjksfhasdjkncxsvnxcm,fdjklfjdkf", // 80
"fdhuafdhasuifhdasuigbdjkbvcjksbdfhduasfhduasifhdasjkfhdasjkfhdjklasfoeurieoiruwiowurieoureik", // 90
"dshfudahfduiashfduiasnvdjkvnuiarheuirheiodfhdjksafhuiheuiafheaskfdhjkasfhdjkashfdjkashfdjkasuipiuk890f", // 100
};
}
@GenerateMicroBenchmark
public StringBuilder doIt(BenchmarkState state) {
StringBuilder strBuf = new StringBuilder();
for (String s : state.strs) {
strBuf.append(s);
}
return strBuf;
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(".*" + JMHSample_96_StringAppend.class.getSimpleName() + ".*")
.warmupIterations(5)
.measurementIterations(5)
.forks(1)
.build();
new Runner(opt).run();
}
}
More information about the hotspot-compiler-dev
mailing list