feat: JMHExample13

This commit is contained in:
Bunny 2025-01-19 15:49:55 +08:00
parent c8c2a0e8bc
commit e327a1ca33
1 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,47 @@
package cn.bunny.jmh;
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;
import java.util.concurrent.atomic.AtomicInteger;
@BenchmarkMode(Mode.AverageTime)
@Fork(1)
@Warmup(iterations = 5)
@Measurement(iterations = 5)
@OutputTimeUnit(TimeUnit.MICROSECONDS)
@State(Scope.Group)
public class JMHExample13 {
private AtomicInteger counter;
public static void main(String[] args) throws RunnerException {
final Options options = new OptionsBuilder()
.include(JMHExample13.class.getSimpleName())
.build();
new Runner(options).run();
}
@Setup
public void setup() {
this.counter = new AtomicInteger();
}
@GroupThreads(5)
@Group("q")
@Benchmark
public void inc() {
this.counter.incrementAndGet();
}
@GroupThreads(5)
@Group("q")
@Benchmark
public int get() {
return this.counter.get();
}
}