feat: JMHExample03
This commit is contained in:
parent
e089a4814d
commit
47a217e0ae
|
@ -0,0 +1,41 @@
|
|||
package cn.bunny;
|
||||
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
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;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@Fork(1)
|
||||
@Warmup(iterations = 5)
|
||||
@Measurement(iterations = 10)
|
||||
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||||
// 设置5个线程进行基准测试
|
||||
@Threads(5)
|
||||
public class JMHExample03 {
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(JMHExample03.class.getSimpleName())
|
||||
.build();
|
||||
new Runner(options).run();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void test(Test test) {
|
||||
test.method();
|
||||
}
|
||||
|
||||
@State(Scope.Thread)
|
||||
public static class Test {
|
||||
public Test() {
|
||||
System.out.println("create instance");
|
||||
}
|
||||
|
||||
public void method() {
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue