feat: JMHExample02
This commit is contained in:
parent
823db4204d
commit
e089a4814d
|
@ -0,0 +1,52 @@
|
|||
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;
|
||||
|
||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||
@State(Scope.Thread)
|
||||
@Measurement(iterations = 5)
|
||||
@Warmup(iterations = 2)
|
||||
public class JMHExample02 {
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
Options options = new OptionsBuilder()
|
||||
.include(JMHExample02.class.getSimpleName())
|
||||
.forks(1)
|
||||
.build();
|
||||
new Runner(options).run();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void test() throws InterruptedException {
|
||||
TimeUnit.MILLISECONDS.sleep(10);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void test2() throws InterruptedException {
|
||||
TimeUnit.MILLISECONDS.sleep(1);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.AverageTime)// 平均响应时间
|
||||
public void test3() throws InterruptedException {
|
||||
TimeUnit.MILLISECONDS.sleep(1);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.Throughput)// 方法吞吐量
|
||||
public void test4() throws InterruptedException {
|
||||
TimeUnit.MILLISECONDS.sleep(1);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.SampleTime)// 方法采样时间
|
||||
public void test5() throws InterruptedException {
|
||||
TimeUnit.MILLISECONDS.sleep(1);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue