Good, this demonstrates the gain from specializing o.getClass() ==
ArrayList.class, which is most of the speed-up here as well as in my own
micro:
Patched:
Method Millis Ratio
ArrayList equals 17 1.000
ArrayList$SubList equals 108 6.312
CopyOnWriteArrayList equals 67 3.942
Baseline:
Method Millis Ratio
ArrayList equals 139 1.000
ArrayList$SubList equals 133 0.956
CopyOnWriteArrayList equals 59 0.429
Even without peeling I think we should be able to make ArrayList and
ArrayList$SubList equals as fast as COWAL, so I'll investigate why they
still differ.
/Claes
On 2018-05-12 00:49, Martin Buchholz wrote:
Yet another microbenchmark coming your way. Embarrassing to have
COWAL win all these so handily.
--- IteratorMicroBenchmark.java11 May 2018 18:19:10 -00001.45
+++ IteratorMicroBenchmark.java11 May 2018 22:35:32 -00001.46
@@ -564,6 +564,12 @@
sum[0] = 0;
x.replaceAll(sneakyAdder);
check.sum(sum[0]);}}},
+ new Job(klazz + " equals") {
+ public void work() throws Throwable {
+ ArrayList<Integer> copy = new ArrayList<>(x);
+ for (int i = 0; i < iterations; i++) {
+ if (!x.equals(copy))
+ throw new AssertionError();}}},
new Job(klazz + " hashCode") {
public void work() throws Throwable {
int hashCode = Arrays.hashCode(x.toArray());
C2:
Method Millis Ratio
ArrayList equals 58 1.000
ArrayList$SubList equals 72 1.240
LinkedList equals 101 1.739
AbstractList$SubList equals 164 2.822
Vector equals 162 2.790
SynchronizedRandomAccessList equals 182 3.129
CopyOnWriteArrayList equals 22 0.394
COWSubList equals 19 0.336
C1:
Method Millis Ratio
ArrayList equals 300 1.000
ArrayList$SubList equals 389 1.297
LinkedList equals 328 1.094
AbstractList$SubList equals 349 1.162
Vector equals 263 0.876
SynchronizedRandomAccessList equals 395 1.314
CopyOnWriteArrayList equals 78 0.262
COWSubList equals 80 0.269