Skip to content

Commit

Permalink
Add multi threaded micro benchmarking
Browse files Browse the repository at this point in the history
Signed-off-by: Keshava Munegowda <keshava.gowda@gmail.com>
  • Loading branch information
kmgowda committed May 29, 2024
1 parent cbe3790 commit 1d9aa61
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 6 deletions.
67 changes: 62 additions & 5 deletions perl/src/jmh/java/io/perl/benchmark/QueueBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Timeout;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.Runner;
Expand All @@ -32,11 +33,11 @@
//@Fork(value = 2, jvmArgs = {"-Djmh.blackhole.autoDetect=false"})
public class QueueBenchmark {

final private CQueue<Integer> cqueue;
final private ConcurrentLinkedQueue<Integer> clinkedQueue;
final private LinkedBlockingQueue<Integer> linkedbq;
final private AtomicQueue<Integer> atomicQueue;
final private SyncQueue<Integer> syncQueue;
final protected CQueue<Integer> cqueue;
final protected ConcurrentLinkedQueue<Integer> clinkedQueue;
final protected LinkedBlockingQueue<Integer> linkedbq;
final protected AtomicQueue<Integer> atomicQueue;
final protected SyncQueue<Integer> syncQueue;


public QueueBenchmark() {
Expand Down Expand Up @@ -99,6 +100,62 @@ public void syncQueueBenchmark() {
}


@Benchmark
@Fork(value = 1, warmups = 0)
@Timeout(time = 60)
@Warmup(iterations = 0)
@Measurement(iterations = 3)
@Threads(10)
public void cqueueMultiThreadBenchmark() {
cqueue.add(10);
cqueue.poll();
}

@Benchmark
@Fork(value = 1, warmups = 0)
@Timeout(time = 60)
@Warmup(iterations = 0)
@Measurement(iterations = 3)
@Threads(10)
public void concurrentQueueMultiThreadBenchmark() {
clinkedQueue.add(10);
clinkedQueue.poll();
}

@Benchmark
@Fork(value = 1, warmups = 0)
@Timeout(time = 60)
@Warmup(iterations = 0)
@Measurement(iterations = 3)
@Threads(10)
public void linkedBlockingQueueMultiThreadBenchmark() {
linkedbq.add(10);
linkedbq.poll();
}

@Benchmark
@Fork(value = 1, warmups = 0)
@Timeout(time = 60)
@Warmup(iterations = 0)
@Measurement(iterations = 3)
@Threads(10)
public void atomicQueueMultiThreadBenchmark() {
atomicQueue.add(10);
atomicQueue.poll();
}

@Benchmark
@Fork(value = 1, warmups = 0)
@Timeout(time = 60)
@Warmup(iterations = 0)
@Measurement(iterations = 3)
@Threads(10)
public void syncQueueMultiThreadBenchmark() {
syncQueue.add(10);
syncQueue.poll();
}


public static void main(String[] args) throws Exception {
Options opt = new OptionsBuilder()
.exclude("org.openjdk.jmh.benchmarks.*")
Expand Down
3 changes: 2 additions & 1 deletion perl/src/main/java/io/perl/api/impl/AtomicQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ public AtomicQueue() {

@Override
public T poll() {
final Node<T> curHead = head.get();
final Node<T> curHead = head.getAndSet(null);
if (curHead == null) {
return null;
}
final Node<T> nxt = curHead.next.getAndSet(null);
if (nxt == null) {
head.set(curHead);
return null;
}
head.set(nxt);
Expand Down

0 comments on commit 1d9aa61

Please sign in to comment.