Skip to content

Commit

Permalink
Merge pull request #432 from kmgowda/kmg-jmh-1
Browse files Browse the repository at this point in the history
Add JMH microbenchmarks

Signed-off-by: Keshava Munegowda <keshava.gowda@gmail.com>
  • Loading branch information
kmgowda authored May 26, 2024
2 parents 6b3d57e + a37037f commit 09ff066
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 2 deletions.
1 change: 1 addition & 0 deletions checkstyle/import-control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@
<allow pkg="com.couchbase" />
<allow pkg="net.rubyeye" />
<allow pkg="software.amazon"/>
<allow pkg="org.openjdk.jmh"/>
</import-control>
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import io.perl.api.Queue;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;

public class LinkedBQueue<T> extends LinkedBlockingDeque<T> implements Queue<T> {
public class LinkedBQueue<T> extends LinkedBlockingQueue<T> implements Queue<T> {
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ sshdVersion=2.10.0
HdrHistogramVersion=2.1.12
jetbrainVersion=24.0.1
jmxPrometheusVersion=0.20.0
jmhGradleVersion=0.7.2
jmhVersion=1.37

eclipseCollectionVersion=11.1.0

Expand Down
11 changes: 11 additions & 0 deletions perl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
apply plugin: 'java-library'
apply plugin: "maven-publish"
apply plugin: "com.github.spotbugs"
apply plugin: "me.champeau.jmh"


buildscript {
repositories {
Expand All @@ -22,6 +24,7 @@ buildscript {
}
dependencies {
classpath group: 'org.nosphere.apache', name: 'creadur-rat-gradle', version: apacheRatVersion
classpath group: 'me.champeau.jmh', name: 'jmh-gradle-plugin', version: jmhGradleVersion
}
}

Expand All @@ -48,6 +51,14 @@ dependencies {
api group: 'com.google.guava', name: 'guava', version: guavaVersion
implementation group: 'org.eclipse.collections', name: 'eclipse-collections', version: eclipseCollectionVersion
implementation group: 'org.jetbrains', name: 'annotations', version: jetbrainVersion
testImplementation group: 'org.openjdk.jmh', name: 'jmh-core', version: jmhVersion
annotationProcessor group: 'org.openjdk.jmh', name: 'jmh-generator-annprocess', version: jmhVersion
testImplementation group: 'org.openjdk.jmh', name: 'jmh-core-benchmarks', version: jmhVersion
}

jmh {
jvmArgs = ["-Djmh.blackhole.autoDetect=false"]
excludes = ['org.openjdk.jmh.benchmarks',]
}

task updateDocs(dependsOn: javadoc) {
Expand Down
98 changes: 98 additions & 0 deletions perl/src/jmh/java/io/perl/benchmark/QueueBenchmark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**
* Copyright (c) KMG. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*/

package io.perl.benchmark;

import io.perl.api.impl.AtomicQueue;
import io.perl.api.impl.CQueue;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Timeout;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.LinkedBlockingQueue;


@State(Scope.Thread)
//@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;


public QueueBenchmark() {
cqueue = new CQueue<>();
clinkedQueue = new ConcurrentLinkedQueue<>();
linkedbq = new LinkedBlockingQueue<>();
atomicQueue = new AtomicQueue<>();
}

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

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

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

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

public static void main(String[] args) throws Exception {
Options opt = new OptionsBuilder()
.exclude("org.openjdk.jmh.benchmarks.*")
.include("io.perl.benchmark.QueueBenchmark.*")
.forks(1)
.build();

new Runner(opt).run();
}
}


0 comments on commit 09ff066

Please sign in to comment.