53 lines
1.5 KiB
Java
53 lines
1.5 KiB
Java
|
package jmh;
|
||
|
|
||
|
import org.openjdk.jmh.annotations.*;
|
||
|
import org.openjdk.jmh.profile.StackProfiler;
|
||
|
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 org.openjdk.jmh.runner.options.TimeValue;
|
||
|
|
||
|
import java.util.concurrent.BlockingDeque;
|
||
|
import java.util.concurrent.LinkedBlockingDeque;
|
||
|
import java.util.concurrent.TimeUnit;
|
||
|
|
||
|
@BenchmarkMode(Mode.AverageTime)
|
||
|
@Fork(1)
|
||
|
@Warmup(iterations = 5)
|
||
|
@Measurement(iterations = 5)
|
||
|
@OutputTimeUnit(TimeUnit.MICROSECONDS)
|
||
|
@State(Scope.Group)
|
||
|
public class JMHExample17 {
|
||
|
private final static int VALUE = Integer.MAX_VALUE;
|
||
|
private BlockingDeque<Integer> queue;
|
||
|
|
||
|
public static void main(String[] args) throws RunnerException {
|
||
|
final Options options = new OptionsBuilder()
|
||
|
.include(JMHExample17.class.getSimpleName())
|
||
|
.timeout(TimeValue.seconds(10))
|
||
|
.addProfiler(StackProfiler.class)
|
||
|
.build();
|
||
|
new Runner(options).run();
|
||
|
}
|
||
|
|
||
|
@Setup
|
||
|
public void init() {
|
||
|
this.queue = new LinkedBlockingDeque<>(10);
|
||
|
}
|
||
|
|
||
|
@GroupThreads(5)
|
||
|
@Group("blockingQueue")
|
||
|
@Benchmark
|
||
|
public void put() throws InterruptedException {
|
||
|
this.queue.put(VALUE);
|
||
|
}
|
||
|
|
||
|
@GroupThreads(5)
|
||
|
@Group("blockingQueue")
|
||
|
@Benchmark
|
||
|
public int take() throws InterruptedException {
|
||
|
return this.queue.take();
|
||
|
}
|
||
|
}
|