Add benchmark for a comparison of the custom made removeAll
method vs an implementation that uses removeIf
This commit is contained in:
2017-12-20 17:51:15 +01:00
parent 45dd73d8f3
commit 1681183474
2 changed files with 77 additions and 0 deletions

View File

@@ -1,3 +1,16 @@
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.5"
}
}
apply plugin: 'java' apply plugin: 'java'
apply plugin: 'eclipse' apply plugin: 'eclipse'
@@ -9,6 +22,7 @@ subprojects {
apply plugin: 'eclipse' apply plugin: 'eclipse'
apply plugin: 'maven' apply plugin: 'maven'
apply plugin: 'maven-publish' apply plugin: 'maven-publish'
apply plugin: 'me.champeau.gradle.jmh'
// java compatibility version // java compatibility version
sourceCompatibility = 1.8 sourceCompatibility = 1.8
@@ -49,6 +63,10 @@ subprojects {
dependencies { dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group: 'junit', name: 'junit', version: '4.12'
} }
jmh {
jvmArgsAppend = "-ea"
}
} }
task wrapper(type: Wrapper) { task wrapper(type: Wrapper) {

View File

@@ -0,0 +1,59 @@
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 BenchmarkRemoveAll {
private IntList base = null;
private IntList remove = null;
@Setup
public void setup() throws Exception {
final int values = 100_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 testRemoveAll() throws Exception {
final IntList tmp = base.clone();
tmp.removeAll(remove);
}
@Benchmark
public void testRemoveAll_withRemoveIf() throws Exception {
final IntList tmp = base.clone();
tmp.removeIf((val, index) -> remove.indexOf(val) >= 0);
}
}