From e089a4814d55bef9739844ca0bd81808ec0fddcf Mon Sep 17 00:00:00 2001 From: Bunny <1319900154@qq.com> Date: Sun, 19 Jan 2025 12:18:24 +0800 Subject: [PATCH] feat: JMHExample02 --- .../src/main/java/cn/bunny/JMHExample02.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 multithreading1/src/main/java/cn/bunny/JMHExample02.java diff --git a/multithreading1/src/main/java/cn/bunny/JMHExample02.java b/multithreading1/src/main/java/cn/bunny/JMHExample02.java new file mode 100644 index 0000000..58813ad --- /dev/null +++ b/multithreading1/src/main/java/cn/bunny/JMHExample02.java @@ -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); + } +} \ No newline at end of file