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.concurrent.TimeUnit;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
import java.util.stream.LongStream;
|
||||||
|
|
||||||
import org.openjdk.jmh.annotations.Benchmark;
|
import org.openjdk.jmh.annotations.Benchmark;
|
||||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||||
@@ -25,61 +26,112 @@ public class BenchmarkUnionIntersection {
|
|||||||
@Param({ "10000", "20000" })
|
@Param({ "10000", "20000" })
|
||||||
private int values;
|
private int values;
|
||||||
|
|
||||||
private IntList aSorted = null;
|
private IntList aIntSorted = null;
|
||||||
private IntList bSorted = null;
|
private IntList bIntSorted = null;
|
||||||
private IntList cUnsorted = null;
|
private IntList cIntUnsorted = null;
|
||||||
private IntList dUnsorted = null;
|
private IntList dIntUnsorted = null;
|
||||||
|
|
||||||
|
private LongList aLongSorted = null;
|
||||||
|
private LongList bLongSorted = null;
|
||||||
|
private LongList cLongUnsorted = null;
|
||||||
|
private LongList dLongUnsorted = null;
|
||||||
|
|
||||||
@Setup
|
@Setup
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
|
|
||||||
aSorted = IntList.of();
|
aIntSorted = IntList.of();
|
||||||
IntStream.range(0, values).forEachOrdered(aSorted::add);
|
IntStream.range(0, values).forEachOrdered(aIntSorted::add);
|
||||||
aSorted.sort();
|
aIntSorted.sort();
|
||||||
|
|
||||||
bSorted = IntList.of();
|
bIntSorted = IntList.of();
|
||||||
IntStream.range(0, values).forEachOrdered(bSorted::add);
|
IntStream.range(0, values).forEachOrdered(bIntSorted::add);
|
||||||
bSorted.sort();
|
bIntSorted.sort();
|
||||||
|
|
||||||
cUnsorted = IntList.of();
|
cIntUnsorted = IntList.of();
|
||||||
IntStream.range(0, values).forEachOrdered(cUnsorted::add);
|
IntStream.range(0, values).forEachOrdered(cIntUnsorted::add);
|
||||||
cUnsorted.shuffle();
|
cIntUnsorted.shuffle();
|
||||||
|
|
||||||
dUnsorted = IntList.of();
|
dIntUnsorted = IntList.of();
|
||||||
IntStream.range(0, values).forEachOrdered(dUnsorted::add);
|
IntStream.range(0, values).forEachOrdered(dIntUnsorted::add);
|
||||||
dUnsorted.shuffle();
|
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
|
@TearDown
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
aSorted = null;
|
aIntSorted = null;
|
||||||
bSorted = null;
|
bIntSorted = null;
|
||||||
cUnsorted = null;
|
cIntUnsorted = null;
|
||||||
dUnsorted = null;
|
dIntUnsorted = null;
|
||||||
|
aLongSorted = null;
|
||||||
|
bLongSorted = null;
|
||||||
|
cLongUnsorted = null;
|
||||||
|
dLongUnsorted = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public void testUnionSortedLists() throws Exception {
|
public void testIntUnionSortedLists() throws Exception {
|
||||||
|
|
||||||
IntList.union(aSorted, bSorted);
|
IntList.union(aIntSorted, bIntSorted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public void testIntersectionSortedLists() throws Exception {
|
public void testIntIntersectionSortedLists() throws Exception {
|
||||||
|
|
||||||
IntList.intersection(aSorted, bSorted);
|
IntList.intersection(aIntSorted, bIntSorted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public void testUnionUnsortedLists() throws Exception {
|
public void testIntUnionUnsortedLists() throws Exception {
|
||||||
|
|
||||||
IntList.union(cUnsorted, dUnsorted);
|
IntList.union(cIntUnsorted, dIntUnsorted);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@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.concurrent.TimeUnit;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
import java.util.stream.LongStream;
|
||||||
|
|
||||||
import org.openjdk.jmh.annotations.Benchmark;
|
import org.openjdk.jmh.annotations.Benchmark;
|
||||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||||
@@ -20,31 +21,61 @@ import org.openjdk.jmh.annotations.Warmup;
|
|||||||
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
|
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
|
||||||
@Fork(1)
|
@Fork(1)
|
||||||
public class BenchmarkUniq {
|
public class BenchmarkUniq {
|
||||||
private IntList base = null;
|
private IntList aIntSorted = null;
|
||||||
private IntList remove = null;
|
private IntList bIntUnsorted = null;
|
||||||
|
|
||||||
|
private LongList aLongSorted = null;
|
||||||
|
private LongList bLongUnsorted = null;
|
||||||
|
|
||||||
@Setup
|
@Setup
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
|
|
||||||
final int values = 10_000;
|
final int values = 10_000;
|
||||||
base = IntList.of();
|
aIntSorted = IntList.of();
|
||||||
IntStream.range(0, values).forEachOrdered(i -> base.add(i));
|
IntStream.range(0, values).forEachOrdered(aIntSorted::add);
|
||||||
base.sort();
|
aIntSorted.sort();
|
||||||
|
|
||||||
remove = IntList.of();
|
bIntUnsorted = IntList.of();
|
||||||
IntStream.range(0, 50).forEachOrdered(i -> remove.add(i));
|
IntStream.range(0, values).forEachOrdered(bIntUnsorted::add);
|
||||||
remove.sort();
|
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
|
@TearDown
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
base = null;
|
aIntSorted = null;
|
||||||
remove = null;
|
bIntUnsorted = null;
|
||||||
|
|
||||||
|
aLongSorted = null;
|
||||||
|
bLongUnsorted = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@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