File: IteratorMicroBenchmark.java

package info (click to toggle)
openjdk-11 11.0.4%2B11-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 757,028 kB
  • sloc: java: 5,016,041; xml: 1,191,974; cpp: 934,731; ansic: 555,697; sh: 24,299; objc: 12,703; python: 3,602; asm: 3,415; makefile: 2,772; awk: 351; sed: 172; perl: 114; jsp: 24; csh: 3
file content (580 lines) | stat: -rw-r--r-- 25,008 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
/*
 * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/*
 * @test
 * @summary micro-benchmark correctness mode
 * @run main IteratorMicroBenchmark iterations=1 size=8 warmup=0
 */

import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.stream.Collectors.summingInt;
import static java.util.stream.Collectors.toCollection;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Spliterator;
import java.util.Vector;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.LongAdder;
import java.util.function.UnaryOperator;
import java.util.regex.Pattern;
import java.util.stream.Stream;

/**
 * Usage: [iterations=N] [size=N] [filter=REGEXP] [warmup=SECONDS]
 *
 * To run this in micro-benchmark mode, simply run as a normal java program.
 * Be patient; this program runs for a very long time.
 * For faster runs, restrict execution using command line args.
 *
 * This is an interface based version of ArrayList/IteratorMicroBenchmark
 *
 * @author Martin Buchholz
 */
public class IteratorMicroBenchmark {
    abstract static class Job {
        private final String name;
        public Job(String name) { this.name = name; }
        public String name() { return name; }
        public abstract void work() throws Throwable;
        public void run() {
            try { work(); }
            catch (Throwable ex) {
                // current job cannot always be deduced from stacktrace.
                throw new RuntimeException("Job failed: " + name(), ex);
            }
        }
    }

    final int iterations;
    final int size;             // number of elements in collections
    final double warmupSeconds;
    final long warmupNanos;
    final Pattern nameFilter;   // select subset of Jobs to run
    final boolean reverse;      // reverse order of Jobs
    final boolean shuffle;      // randomize order of Jobs

    IteratorMicroBenchmark(String[] args) {
        iterations    = intArg(args, "iterations", 10_000);
        size          = intArg(args, "size", 1000);
        warmupSeconds = doubleArg(args, "warmup", 7.0);
        nameFilter    = patternArg(args, "filter");
        reverse       = booleanArg(args, "reverse");
        shuffle       = booleanArg(args, "shuffle");

        warmupNanos = (long) (warmupSeconds * (1000L * 1000L * 1000L));
    }

    // --------------- GC finalization infrastructure ---------------

    /** No guarantees, but effective in practice. */
    static void forceFullGc() {
        long timeoutMillis = 1000L;
        CountDownLatch finalized = new CountDownLatch(1);
        ReferenceQueue<Object> queue = new ReferenceQueue<>();
        WeakReference<Object> ref = new WeakReference<>(
            new Object() { protected void finalize() { finalized.countDown(); }},
            queue);
        try {
            for (int tries = 3; tries--> 0; ) {
                System.gc();
                if (finalized.await(timeoutMillis, MILLISECONDS)
                    && queue.remove(timeoutMillis) != null
                    && ref.get() == null) {
                    System.runFinalization(); // try to pick up stragglers
                    return;
                }
                timeoutMillis *= 4;
            }
        } catch (InterruptedException unexpected) {
            throw new AssertionError("unexpected InterruptedException");
        }
        throw new AssertionError("failed to do a \"full\" gc");
    }

    /**
     * Runs each job for long enough that all the runtime compilers
     * have had plenty of time to warm up, i.e. get around to
     * compiling everything worth compiling.
     * Returns array of average times per job per run.
     */
    long[] time0(List<Job> jobs) {
        final int size = jobs.size();
        long[] nanoss = new long[size];
        for (int i = 0; i < size; i++) {
            if (warmupNanos > 0) forceFullGc();
            Job job = jobs.get(i);
            long totalTime;
            int runs = 0;
            long startTime = System.nanoTime();
            do { job.run(); runs++; }
            while ((totalTime = System.nanoTime() - startTime) < warmupNanos);
            nanoss[i] = totalTime/runs;
        }
        return nanoss;
    }

    void time(List<Job> jobs) throws Throwable {
        if (warmupNanos > 0) time0(jobs); // Warm up run
        final int size = jobs.size();
        final long[] nanoss = time0(jobs); // Real timing run
        final long[] milliss = new long[size];
        final double[] ratios = new double[size];

        final String nameHeader   = "Method";
        final String millisHeader = "Millis";
        final String ratioHeader  = "Ratio";

        int nameWidth   = nameHeader.length();
        int millisWidth = millisHeader.length();
        int ratioWidth  = ratioHeader.length();

        for (int i = 0; i < size; i++) {
            nameWidth = Math.max(nameWidth, jobs.get(i).name().length());

            milliss[i] = nanoss[i]/(1000L * 1000L);
            millisWidth = Math.max(millisWidth,
                                   String.format("%d", milliss[i]).length());

            ratios[i] = (double) nanoss[i] / (double) nanoss[0];
            ratioWidth = Math.max(ratioWidth,
                                  String.format("%.3f", ratios[i]).length());
        }

        String format = String.format("%%-%ds %%%dd %%%d.3f%%n",
                                      nameWidth, millisWidth, ratioWidth);
        String headerFormat = String.format("%%-%ds %%%ds %%%ds%%n",
                                            nameWidth, millisWidth, ratioWidth);
        System.out.printf(headerFormat, "Method", "Millis", "Ratio");

        // Print out absolute and relative times, calibrated against first job
        for (int i = 0; i < size; i++)
            System.out.printf(format, jobs.get(i).name(), milliss[i], ratios[i]);
    }

    private static String keywordValue(String[] args, String keyword) {
        for (String arg : args)
            if (arg.startsWith(keyword))
                return arg.substring(keyword.length() + 1);
        return null;
    }

    private static int intArg(String[] args, String keyword, int defaultValue) {
        String val = keywordValue(args, keyword);
        return (val == null) ? defaultValue : Integer.parseInt(val);
    }

    private static double doubleArg(String[] args, String keyword, double defaultValue) {
        String val = keywordValue(args, keyword);
        return (val == null) ? defaultValue : Double.parseDouble(val);
    }

    private static Pattern patternArg(String[] args, String keyword) {
        String val = keywordValue(args, keyword);
        return (val == null) ? null : Pattern.compile(val);
    }

    private static boolean booleanArg(String[] args, String keyword) {
        String val = keywordValue(args, keyword);
        if (val == null || val.equals("false")) return false;
        if (val.equals("true")) return true;
        throw new IllegalArgumentException(val);
    }

    private static void deoptimize(int sum) {
        if (sum == 42)
            System.out.println("the answer");
    }

    private static <T> Iterable<T> backwards(final List<T> list) {
        return new Iterable<T>() {
            public Iterator<T> iterator() {
                return new Iterator<T>() {
                    final ListIterator<T> it = list.listIterator(list.size());
                    public boolean hasNext() { return it.hasPrevious(); }
                    public T next()          { return it.previous(); }
                    public void remove()     {        it.remove(); }};}};
    }

    // Checks for correctness *and* prevents loop optimizations
    static class Check {
        private int sum;
        public void sum(int sum) {
            if (this.sum == 0)
                this.sum = sum;
            if (this.sum != sum)
                throw new AssertionError("Sum mismatch");
        }
    }
    volatile Check check = new Check();

    public static void main(String[] args) throws Throwable {
        new IteratorMicroBenchmark(args).run();
    }

    HashMap<Class<?>, String> goodClassName = new HashMap<>();

    String goodClassName(Class<?> klazz) {
        return goodClassName.computeIfAbsent(
            klazz,
            k -> {
                String simple = k.getSimpleName();
                return (simple.equals("SubList")) // too simple!
                    ? k.getName().replaceFirst(".*\\.", "")
                    : simple;
            });
    }

    static List<Integer> makeSubList(List<Integer> list) {
        final ThreadLocalRandom rnd = ThreadLocalRandom.current();
        int size = list.size();
        if (size <= 2) return list.subList(0, size);
        List<Integer> subList = list.subList(rnd.nextInt(0, 2),
                                             size - rnd.nextInt(0, 2));
        List<Integer> copy = new ArrayList<>(list);
        subList.clear();
        subList.addAll(copy);
        return subList;
    }

    void run() throws Throwable {
        final ArrayList<Integer> al = new ArrayList<>(size);

        // Populate collections with random data
        final ThreadLocalRandom rnd = ThreadLocalRandom.current();
        for (int i = 0; i < size; i++)
            al.add(rnd.nextInt(size));

        final ArrayDeque<Integer> ad = new ArrayDeque<>(al);
        final ArrayBlockingQueue<Integer> abq = new ArrayBlockingQueue<>(al.size());
        abq.addAll(al);

        // shuffle circular array elements so they wrap
        for (int i = 0, n = rnd.nextInt(size); i < n; i++) {
            ad.addLast(ad.removeFirst());
            abq.add(abq.remove());
        }

        ArrayList<Job> jobs = Stream.<Collection<Integer>>of(
                al, ad, abq,
                makeSubList(new ArrayList<>(al)),
                new LinkedList<>(al),
                makeSubList(new LinkedList<>(al)),
                new PriorityQueue<>(al),
                new Vector<>(al),
                makeSubList(new Vector<>(al)),
                new CopyOnWriteArrayList<>(al),
                makeSubList(new CopyOnWriteArrayList<>(al)),
                new ConcurrentLinkedQueue<>(al),
                new ConcurrentLinkedDeque<>(al),
                new LinkedBlockingQueue<>(al),
                new LinkedBlockingDeque<>(al),
                new LinkedTransferQueue<>(al),
                new PriorityBlockingQueue<>(al))
            .flatMap(x -> jobs(x))
            .filter(job ->
                nameFilter == null || nameFilter.matcher(job.name()).find())
            .collect(toCollection(ArrayList::new));

        if (reverse) Collections.reverse(jobs);
        if (shuffle) Collections.shuffle(jobs);

        time(jobs);
    }

    @SafeVarargs @SuppressWarnings("varargs")
    private static <T> Stream<T> concatStreams(Stream<T> ... streams) {
        return Stream.of(streams).flatMap(s -> s);
    }

    Stream<Job> jobs(Collection<Integer> x) {
        return concatStreams(
            collectionJobs(x),

            (x instanceof Deque)
            ? dequeJobs((Deque<Integer>)x)
            : Stream.empty(),

            (x instanceof List)
            ? listJobs((List<Integer>)x)
            : Stream.empty());
    }

    Object sneakyAdder(int[] sneakySum) {
        return new Object() {
            public int hashCode() { throw new AssertionError(); }
            public boolean equals(Object z) {
                sneakySum[0] += (int) z; return false; }};
    }

    Stream<Job> collectionJobs(Collection<Integer> x) {
        final String klazz = goodClassName(x.getClass());
        return Stream.of(
            new Job(klazz + " iterate for loop") {
                public void work() throws Throwable {
                    for (int i = 0; i < iterations; i++) {
                        int sum = 0;
                        for (Integer n : x)
                            sum += n;
                        check.sum(sum);}}},
            new Job(klazz + " iterator().forEachRemaining()") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        x.iterator().forEachRemaining(n -> sum[0] += n);
                        check.sum(sum[0]);}}},
            new Job(klazz + " spliterator().tryAdvance()") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        Spliterator<Integer> spliterator = x.spliterator();
                        do {} while (spliterator.tryAdvance(n -> sum[0] += n));
                        check.sum(sum[0]);}}},
            new Job(klazz + " spliterator().forEachRemaining()") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        x.spliterator().forEachRemaining(n -> sum[0] += n);
                        check.sum(sum[0]);}}},
            new Job(klazz + " removeIf") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        if (x.removeIf(n -> { sum[0] += n; return false; }))
                            throw new AssertionError();
                        check.sum(sum[0]);}}},
            new Job(klazz + " contains") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    Object sneakyAdder = sneakyAdder(sum);
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        if (x.contains(sneakyAdder)) throw new AssertionError();
                        check.sum(sum[0]);}}},
            new Job(klazz + " containsAll") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    Collection<Object> sneakyAdderCollection =
                        Collections.singleton(sneakyAdder(sum));
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        if (x.containsAll(sneakyAdderCollection))
                            throw new AssertionError();
                        check.sum(sum[0]);}}},
            new Job(klazz + " remove(Object)") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    Object sneakyAdder = sneakyAdder(sum);
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        if (x.remove(sneakyAdder)) throw new AssertionError();
                        check.sum(sum[0]);}}},
            new Job(klazz + " forEach") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        x.forEach(n -> sum[0] += n);
                        check.sum(sum[0]);}}},
            new Job(klazz + " toArray()") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        for (Object o : x.toArray())
                            sum[0] += (Integer) o;
                        check.sum(sum[0]);}}},
            new Job(klazz + " toArray(a)") {
                public void work() throws Throwable {
                    Integer[] a = new Integer[x.size()];
                    int[] sum = new int[1];
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        x.toArray(a);
                        for (Object o : a)
                            sum[0] += (Integer) o;
                        check.sum(sum[0]);}}},
            new Job(klazz + " toArray(empty)") {
                public void work() throws Throwable {
                    Integer[] empty = new Integer[0];
                    int[] sum = new int[1];
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        for (Integer o : x.toArray(empty))
                            sum[0] += o;
                        check.sum(sum[0]);}}},
            new Job(klazz + " stream().forEach") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        x.stream().forEach(n -> sum[0] += n);
                        check.sum(sum[0]);}}},
            new Job(klazz + " stream().mapToInt") {
                public void work() throws Throwable {
                    for (int i = 0; i < iterations; i++) {
                        check.sum(x.stream().mapToInt(e -> e).sum());}}},
            new Job(klazz + " stream().collect") {
                public void work() throws Throwable {
                    for (int i = 0; i < iterations; i++) {
                        check.sum(x.stream()
                                  .collect(summingInt(e -> e)));}}},
            new Job(klazz + " stream()::iterator") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        for (Integer o : (Iterable<Integer>) x.stream()::iterator)
                            sum[0] += o;
                        check.sum(sum[0]);}}},
            new Job(klazz + " parallelStream().forEach") {
                public void work() throws Throwable {
                    for (int i = 0; i < iterations; i++) {
                        LongAdder sum = new LongAdder();
                        x.parallelStream().forEach(n -> sum.add(n));
                        check.sum((int) sum.sum());}}},
            new Job(klazz + " parallelStream().mapToInt") {
                public void work() throws Throwable {
                    for (int i = 0; i < iterations; i++) {
                        check.sum(x.parallelStream().mapToInt(e -> e).sum());}}},
            new Job(klazz + " parallelStream().collect") {
                public void work() throws Throwable {
                    for (int i = 0; i < iterations; i++) {
                        check.sum(x.parallelStream()
                                  .collect(summingInt(e -> e)));}}},
            new Job(klazz + " parallelStream()::iterator") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        for (Integer o : (Iterable<Integer>) x.parallelStream()::iterator)
                            sum[0] += o;
                        check.sum(sum[0]);}}});
    }

    Stream<Job> dequeJobs(Deque<Integer> x) {
        String klazz = goodClassName(x.getClass());
        return Stream.of(
            new Job(klazz + " descendingIterator() loop") {
                public void work() throws Throwable {
                    for (int i = 0; i < iterations; i++) {
                        int sum = 0;
                        Iterator<Integer> it = x.descendingIterator();
                        while (it.hasNext())
                            sum += it.next();
                        check.sum(sum);}}},
            new Job(klazz + " descendingIterator().forEachRemaining()") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        x.descendingIterator().forEachRemaining(n -> sum[0] += n);
                        check.sum(sum[0]);}}});
    }

    Stream<Job> listJobs(List<Integer> x) {
        final String klazz = goodClassName(x.getClass());
        return Stream.of(
            new Job(klazz + " listIterator forward loop") {
                public void work() throws Throwable {
                    for (int i = 0; i < iterations; i++) {
                        int sum = 0;
                        ListIterator<Integer> it = x.listIterator();
                        while (it.hasNext())
                            sum += it.next();
                        check.sum(sum);}}},
            new Job(klazz + " listIterator backward loop") {
                public void work() throws Throwable {
                    for (int i = 0; i < iterations; i++) {
                        int sum = 0;
                        ListIterator<Integer> it = x.listIterator(x.size());
                        while (it.hasPrevious())
                            sum += it.previous();
                        check.sum(sum);}}},
            new Job(klazz + " indexOf") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    Object sneakyAdder = sneakyAdder(sum);
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        if (x.indexOf(sneakyAdder) != -1)
                            throw new AssertionError();
                        check.sum(sum[0]);}}},
            new Job(klazz + " lastIndexOf") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    Object sneakyAdder = sneakyAdder(sum);
                    for (int i = 0; i < iterations; i++) {
                        sum[0] = 0;
                        if (x.lastIndexOf(sneakyAdder) != -1)
                            throw new AssertionError();
                        check.sum(sum[0]);}}},
            new Job(klazz + " replaceAll") {
                public void work() throws Throwable {
                    int[] sum = new int[1];
                    UnaryOperator<Integer> sneakyAdder =
                        x -> { sum[0] += x; return x; };
                    for (int i = 0; i < iterations; i++) {
                        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());
                    for (int i = 0; i < iterations; i++) {
                        if (x.hashCode() != hashCode)
                            throw new AssertionError();}}});
    }
}