add JMH tests for union of long list and uniq of lon/int list
This commit is contained in:
@@ -2,6 +2,7 @@ package org.lucares.collections;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
@@ -25,61 +26,112 @@ public class BenchmarkUnionIntersection {
|
||||
@Param({ "10000", "20000" })
|
||||
private int values;
|
||||
|
||||
private IntList aSorted = null;
|
||||
private IntList bSorted = null;
|
||||
private IntList cUnsorted = null;
|
||||
private IntList dUnsorted = null;
|
||||
private IntList aIntSorted = null;
|
||||
private IntList bIntSorted = null;
|
||||
private IntList cIntUnsorted = null;
|
||||
private IntList dIntUnsorted = null;
|
||||
|
||||
private LongList aLongSorted = null;
|
||||
private LongList bLongSorted = null;
|
||||
private LongList cLongUnsorted = null;
|
||||
private LongList dLongUnsorted = null;
|
||||
|
||||
@Setup
|
||||
public void setup() throws Exception {
|
||||
|
||||
aSorted = IntList.of();
|
||||
IntStream.range(0, values).forEachOrdered(aSorted::add);
|
||||
aSorted.sort();
|
||||
aIntSorted = IntList.of();
|
||||
IntStream.range(0, values).forEachOrdered(aIntSorted::add);
|
||||
aIntSorted.sort();
|
||||
|
||||
bSorted = IntList.of();
|
||||
IntStream.range(0, values).forEachOrdered(bSorted::add);
|
||||
bSorted.sort();
|
||||
bIntSorted = IntList.of();
|
||||
IntStream.range(0, values).forEachOrdered(bIntSorted::add);
|
||||
bIntSorted.sort();
|
||||
|
||||
cUnsorted = IntList.of();
|
||||
IntStream.range(0, values).forEachOrdered(cUnsorted::add);
|
||||
cUnsorted.shuffle();
|
||||
cIntUnsorted = IntList.of();
|
||||
IntStream.range(0, values).forEachOrdered(cIntUnsorted::add);
|
||||
cIntUnsorted.shuffle();
|
||||
|
||||
dUnsorted = IntList.of();
|
||||
IntStream.range(0, values).forEachOrdered(dUnsorted::add);
|
||||
dUnsorted.shuffle();
|
||||
dIntUnsorted = IntList.of();
|
||||
IntStream.range(0, values).forEachOrdered(dIntUnsorted::add);
|
||||
dIntUnsorted.shuffle();
|
||||
|
||||
// -----------------------
|
||||
|
||||
aLongSorted = LongList.of();
|
||||
LongStream.range(0, values).forEachOrdered(aLongSorted::add);
|
||||
aLongSorted.sort();
|
||||
|
||||
bLongSorted = LongList.of();
|
||||
LongStream.range(0, values).forEachOrdered(bLongSorted::add);
|
||||
bLongSorted.sort();
|
||||
|
||||
cLongUnsorted = LongList.of();
|
||||
LongStream.range(0, values).forEachOrdered(cLongUnsorted::add);
|
||||
cLongUnsorted.shuffle();
|
||||
|
||||
dLongUnsorted = LongList.of();
|
||||
LongStream.range(0, values).forEachOrdered(dLongUnsorted::add);
|
||||
dLongUnsorted.shuffle();
|
||||
|
||||
}
|
||||
|
||||
@TearDown
|
||||
public void tearDown() {
|
||||
aSorted = null;
|
||||
bSorted = null;
|
||||
cUnsorted = null;
|
||||
dUnsorted = null;
|
||||
aIntSorted = null;
|
||||
bIntSorted = null;
|
||||
cIntUnsorted = null;
|
||||
dIntUnsorted = null;
|
||||
aLongSorted = null;
|
||||
bLongSorted = null;
|
||||
cLongUnsorted = null;
|
||||
dLongUnsorted = null;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testUnionSortedLists() throws Exception {
|
||||
public void testIntUnionSortedLists() throws Exception {
|
||||
|
||||
IntList.union(aSorted, bSorted);
|
||||
IntList.union(aIntSorted, bIntSorted);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testIntersectionSortedLists() throws Exception {
|
||||
public void testIntIntersectionSortedLists() throws Exception {
|
||||
|
||||
IntList.intersection(aSorted, bSorted);
|
||||
IntList.intersection(aIntSorted, bIntSorted);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testUnionUnsortedLists() throws Exception {
|
||||
public void testIntUnionUnsortedLists() throws Exception {
|
||||
|
||||
IntList.union(cUnsorted, dUnsorted);
|
||||
IntList.union(cIntUnsorted, dIntUnsorted);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testIntersectionUnsortedLists() throws Exception {
|
||||
public void testIntIntersectionUnsortedLists() throws Exception {
|
||||
|
||||
IntList.intersection(cUnsorted, dUnsorted);
|
||||
IntList.intersection(cIntUnsorted, dIntUnsorted);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testLongUnionSortedLists() throws Exception {
|
||||
|
||||
LongList.union(aLongSorted, bLongSorted);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testLongIntersectionSortedLists() throws Exception {
|
||||
|
||||
LongList.intersection(aLongSorted, bLongSorted);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testLongUnionUnsortedLists() throws Exception {
|
||||
|
||||
LongList.union(cLongUnsorted, dLongUnsorted);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testLongIntersectionUnsortedLists() throws Exception {
|
||||
|
||||
LongList.intersection(cLongUnsorted, dLongUnsorted);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.lucares.collections;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
@@ -20,31 +21,61 @@ import org.openjdk.jmh.annotations.Warmup;
|
||||
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
|
||||
@Fork(1)
|
||||
public class BenchmarkUniq {
|
||||
private IntList base = null;
|
||||
private IntList remove = null;
|
||||
private IntList aIntSorted = null;
|
||||
private IntList bIntUnsorted = null;
|
||||
|
||||
private LongList aLongSorted = null;
|
||||
private LongList bLongUnsorted = 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();
|
||||
aIntSorted = IntList.of();
|
||||
IntStream.range(0, values).forEachOrdered(aIntSorted::add);
|
||||
aIntSorted.sort();
|
||||
|
||||
remove = IntList.of();
|
||||
IntStream.range(0, 50).forEachOrdered(i -> remove.add(i));
|
||||
remove.sort();
|
||||
bIntUnsorted = IntList.of();
|
||||
IntStream.range(0, values).forEachOrdered(bIntUnsorted::add);
|
||||
bIntUnsorted.shuffle();
|
||||
|
||||
// -----------------------
|
||||
|
||||
aLongSorted = LongList.of();
|
||||
LongStream.range(0, values).forEachOrdered(aLongSorted::add);
|
||||
aLongSorted.sort();
|
||||
|
||||
bLongUnsorted = LongList.of();
|
||||
LongStream.range(0, values).forEachOrdered(bLongUnsorted::add);
|
||||
bLongUnsorted.shuffle();
|
||||
}
|
||||
|
||||
@TearDown
|
||||
public void tearDown() {
|
||||
base = null;
|
||||
remove = null;
|
||||
aIntSorted = null;
|
||||
bIntUnsorted = null;
|
||||
|
||||
aLongSorted = null;
|
||||
bLongUnsorted = null;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testUniq() throws Exception {
|
||||
public void testIntUniqSorted() throws Exception {
|
||||
aIntSorted.clone().uniq();
|
||||
}
|
||||
|
||||
// IntList.union(aSorted, bSorted);
|
||||
@Benchmark
|
||||
public void testIntUniqUnsorted() throws Exception {
|
||||
bIntUnsorted.clone().uniq();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testLongUniqSorted() throws Exception {
|
||||
aLongSorted.clone().uniq();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void testLongUniqUnsorted() throws Exception {
|
||||
bLongUnsorted.clone().uniq();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user