add more JMH tests

This commit is contained in:
2019-09-01 15:47:10 +02:00
parent 0311ecd83c
commit 097b7ab110
3 changed files with 67 additions and 1 deletions

View File

@@ -7,6 +7,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
// run with gradle --no-daemon clean jmh
classpath "me.champeau.gradle:jmh-gradle-plugin:0.5.0-rc-2" classpath "me.champeau.gradle:jmh-gradle-plugin:0.5.0-rc-2"
} }
} }

View File

@@ -8,6 +8,7 @@ import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope; import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.State;
@@ -21,6 +22,9 @@ import org.openjdk.jmh.annotations.Warmup;
@Fork(1) @Fork(1)
public class BenchmarkUnionIntersection { public class BenchmarkUnionIntersection {
@Param({ "10000", "20000" })
private int values;
private IntList aSorted = null; private IntList aSorted = null;
private IntList bSorted = null; private IntList bSorted = null;
private IntList cUnsorted = null; private IntList cUnsorted = null;
@@ -29,7 +33,6 @@ public class BenchmarkUnionIntersection {
@Setup @Setup
public void setup() throws Exception { public void setup() throws Exception {
final int values = 10_000;
aSorted = IntList.of(); aSorted = IntList.of();
IntStream.range(0, values).forEachOrdered(aSorted::add); IntStream.range(0, values).forEachOrdered(aSorted::add);
aSorted.sort(); aSorted.sort();
@@ -67,4 +70,16 @@ public class BenchmarkUnionIntersection {
IntList.intersection(aSorted, bSorted); IntList.intersection(aSorted, bSorted);
} }
@Benchmark
public void testUnionUnsortedLists() throws Exception {
IntList.union(cUnsorted, dUnsorted);
}
@Benchmark
public void testIntersectionUnsortedLists() throws Exception {
IntList.intersection(cUnsorted, dUnsorted);
}
} }

View File

@@ -0,0 +1,50 @@
package org.lucares.collections;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
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;
@State(Scope.Benchmark)
@BenchmarkMode(Mode.Throughput)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(1)
public class BenchmarkUniq {
private IntList base = null;
private IntList remove = null;
@Setup
public void setup() throws Exception {
final int values = 10_000;
base = IntList.of();
IntStream.range(0, values).forEachOrdered(i -> base.add(i));
base.sort();
remove = IntList.of();
IntStream.range(0, 50).forEachOrdered(i -> remove.add(i));
remove.sort();
}
@TearDown
public void tearDown() {
base = null;
remove = null;
}
@Benchmark
public void testUniq() throws Exception {
// IntList.union(aSorted, bSorted);
}
}