Skip to content

Commit

Permalink
Additional JMH test (legacy)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgprudhomme committed Oct 21, 2024
1 parent c40ead3 commit 08547bd
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 10 deletions.
60 changes: 51 additions & 9 deletions RoaringBitmap/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
plugins {
id("me.champeau.gradle.jmh") version "0.5.0"
id("com.github.johnrengelman.shadow") version "6.0.0"
}

buildscript {
repositories {
maven {
Expand Down Expand Up @@ -57,15 +62,19 @@ tasks.compileTestJava {
val deps: Map<String, String> by extra

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:${deps["jupiter"]}")
testImplementation("org.junit.jupiter:junit-jupiter-params:${deps["jupiter"]}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${deps["jupiter"]}")
testImplementation("com.google.guava:guava:${deps["guava"]}")
testImplementation("org.apache.commons:commons-lang3:${deps["commons-lang"]}")
testImplementation("com.esotericsoftware:kryo:5.0.0-RC6")
testImplementation("com.fasterxml.jackson.core", "jackson-databind", "2.10.3")
testImplementation("org.assertj", "assertj-core", "3.23.1")
testImplementation("org.openjdk.jol", "jol-core", "0.16")
implementation("org.junit.jupiter:junit-jupiter-api:${deps["jupiter"]}")
implementation("org.junit.jupiter:junit-jupiter-params:${deps["jupiter"]}")
runtimeOnly("org.junit.jupiter:junit-jupiter-engine:${deps["jupiter"]}")
implementation("org.openjdk.jmh:jmh-core:1.35")
annotationProcessor("org.openjdk.jmh:jmh-generator-annprocess:1.35")
implementation("com.google.guava:guava:${deps["guava"]}")
implementation("org.apache.commons:commons-lang3:${deps["commons-lang"]}")
implementation("com.esotericsoftware:kryo:5.0.0-RC6")
implementation("com.fasterxml.jackson.core", "jackson-databind", "2.10.3")
implementation("org.assertj:assertj-core:3.23.1")
implementation("org.openjdk.jol:jol-core:0.16")
jmhImplementation("org.junit.jupiter:junit-jupiter-api:${deps["jupiter"]}")
jmhRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${deps["jupiter"]}")
}

sourceSets {
Expand Down Expand Up @@ -115,3 +124,36 @@ tasks.test {
// showStandardStreams = true
}
}

jmh {
sourceSets {
getByName("main") {
java.srcDir("src/test/java")
}
}
}

tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
archiveClassifier.set("all")

from(sourceSets["main"].output)
from(sourceSets["test"].output)

manifest {
attributes(
"Main-Class" to "org.openjdk.jmh.Main"
)
}

configurations = listOf(project.configurations.getByName("runtimeClasspath"))
}

tasks.register<JavaExec>("runJmhShadow") {
group = "benchmark"
description = "Runs JMH benchmarks from the shadow JAR."

classpath = files(tasks.named("shadowJar"))

mainClass.set("org.openjdk.jmh.Main")
jvmArgs = listOf("-Xms2G", "-Xmx2G")
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@

import static org.junit.jupiter.api.Assertions.*;

import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Warmup;


class ByteBufferBackedInputStream extends InputStream {

Expand Down Expand Up @@ -99,8 +113,12 @@ public synchronized void write(int b) throws IOException {


@SuppressWarnings({"static-method"})
@State(Scope.Benchmark)
public class TestMemoryMapping {

@Param({"10", "50", "100", "500", "1000", "5000"})
int numThreads;

static ArrayList<ImmutableRoaringBitmap> mappedbitmaps = new ArrayList<ImmutableRoaringBitmap>();

static MappedByteBuffer out;
Expand All @@ -110,6 +128,7 @@ public class TestMemoryMapping {
static File tmpfile;

@AfterAll
@TearDown(Level.Trial)
public static void clearFiles() {
System.out.println("[TestMemoryMapping] Cleaning memory-mapped file.");
out = null;
Expand All @@ -131,6 +150,7 @@ public static boolean equals(ByteBuffer bb1, ByteBuffer bb2) {
}

@BeforeAll
@Setup(Level.Trial)
public static void initFiles() throws IOException {
System.out.println("[TestMemoryMapping] Setting up memory-mapped file. (Can take some time.)");
final ArrayList<Long> offsets = new ArrayList<Long>();
Expand Down Expand Up @@ -358,11 +378,11 @@ public void intersections() {
}

@Test
@Benchmark
public void multithreadingTest() throws InterruptedException, IOException {
System.out.println("[TestMemoryMapping] multithreading test");
final MutableRoaringBitmap rr1 = new MutableRoaringBitmap();

final int numThreads = Runtime.getRuntime().availableProcessors();
final Throwable[] errors = new Throwable[numThreads];

for (int i = 0; i < numThreads; i++) {
Expand Down

0 comments on commit 08547bd

Please sign in to comment.