--- a/jdk/test/java/util/Collection/RemoveMicroBenchmark.java Fri Feb 03 13:24:59 2017 -0800
+++ b/jdk/test/java/util/Collection/RemoveMicroBenchmark.java Fri Feb 03 13:24:59 2017 -0800
@@ -254,7 +254,7 @@
// "iterations=%d size=%d, warmup=%1g, filter=\"%s\"%n",
// iterations, size, warmupSeconds, filter);
- final ArrayList<Integer> al = new ArrayList<Integer>(size);
+ final ArrayList<Integer> al = new ArrayList<>(size);
// Populate collections with random data
final ThreadLocalRandom rnd = ThreadLocalRandom.current();
@@ -333,7 +333,7 @@
Supplier<Collection<Integer>> supplier,
ArrayList<Integer> al) {
return List.of(
- new Job(description + " .removeIf") {
+ new Job(description + " removeIf") {
public void work() throws Throwable {
Collection<Integer> x = supplier.get();
int[] sum = new int[1];
@@ -342,7 +342,21 @@
x.addAll(al);
x.removeIf(n -> { sum[0] += n; return true; });
check.sum(sum[0]);}}},
- new Job(description + " .removeAll") {
+ new Job(description + " removeIf rnd-two-pass") {
+ public void work() throws Throwable {
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+ Collection<Integer> x = supplier.get();
+ int[] sum = new int[1];
+ for (int i = 0; i < iterations; i++) {
+ sum[0] = 0;
+ x.addAll(al);
+ x.removeIf(n -> {
+ boolean b = rnd.nextBoolean();
+ if (b) sum[0] += n;
+ return b; });
+ x.removeIf(n -> { sum[0] += n; return true; });
+ check.sum(sum[0]);}}},
+ new Job(description + " removeAll") {
public void work() throws Throwable {
Collection<Integer> x = supplier.get();
int[] sum = new int[1];
@@ -352,7 +366,7 @@
x.addAll(al);
x.removeAll(universe);
check.sum(sum[0]);}}},
- new Job(description + " .retainAll") {
+ new Job(description + " retainAll") {
public void work() throws Throwable {
Collection<Integer> x = supplier.get();
int[] sum = new int[1];
@@ -375,6 +389,28 @@
it.remove();
}
check.sum(sum[0]);}}},
+ new Job(description + " Iterator.remove-rnd-two-pass") {
+ public void work() throws Throwable {
+ ThreadLocalRandom rnd = ThreadLocalRandom.current();
+ Collection<Integer> x = supplier.get();
+ int[] sum = new int[1];
+ for (int i = 0; i < iterations; i++) {
+ sum[0] = 0;
+ x.addAll(al);
+ for (Iterator<Integer> it = x.iterator();
+ it.hasNext(); ) {
+ Integer e = it.next();
+ if (rnd.nextBoolean()) {
+ sum[0] += e;
+ it.remove();
+ }
+ }
+ for (Iterator<Integer> it = x.iterator();
+ it.hasNext(); ) {
+ sum[0] += it.next();
+ it.remove();
+ }
+ check.sum(sum[0]);}}},
new Job(description + " clear") {
public void work() throws Throwable {
Collection<Integer> x = supplier.get();