ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Collection/RemoveMicroBenchmark.java
Revision: 1.26
Committed: Thu Jan 10 16:46:56 2019 UTC (5 years, 4 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.25: +10 -6 lines
Log Message:
support sublists of immutable lists plus cosmetic improvements

File Contents

# User Rev Content
1 jsr166 1.1 /*
2     * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
3     * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4     *
5     * This code is free software; you can redistribute it and/or modify it
6     * under the terms of the GNU General Public License version 2 only, as
7     * published by the Free Software Foundation.
8     *
9     * This code is distributed in the hope that it will be useful, but WITHOUT
10     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11     * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12     * version 2 for more details (a copy is included in the LICENSE file that
13     * accompanied this code).
14     *
15     * You should have received a copy of the GNU General Public License version
16     * 2 along with this work; if not, write to the Free Software Foundation,
17     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18     *
19     * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20     * or visit www.oracle.com if you need additional information or have any
21     * questions.
22     */
23    
24     /*
25     * @test
26     * @summary micro-benchmark correctness mode
27     * @run main RemoveMicroBenchmark iterations=1 size=8 warmup=0
28     */
29    
30 jsr166 1.24 import static java.util.concurrent.TimeUnit.MILLISECONDS;
31 jsr166 1.22 import static java.util.stream.Collectors.toCollection;
32 jsr166 1.20
33 jsr166 1.24 import java.lang.ref.ReferenceQueue;
34 jsr166 1.1 import java.lang.ref.WeakReference;
35     import java.util.ArrayDeque;
36     import java.util.ArrayList;
37     import java.util.Collection;
38 jsr166 1.5 import java.util.Collections;
39 jsr166 1.1 import java.util.Deque;
40 jsr166 1.22 import java.util.HashMap;
41 jsr166 1.1 import java.util.Iterator;
42     import java.util.LinkedList;
43     import java.util.List;
44     import java.util.ListIterator;
45 jsr166 1.2 import java.util.PriorityQueue;
46 jsr166 1.8 import java.util.Queue;
47 jsr166 1.1 import java.util.Vector;
48     import java.util.concurrent.ArrayBlockingQueue;
49 jsr166 1.7 import java.util.concurrent.BlockingDeque;
50 jsr166 1.3 import java.util.concurrent.BlockingQueue;
51 jsr166 1.1 import java.util.concurrent.ConcurrentLinkedDeque;
52     import java.util.concurrent.ConcurrentLinkedQueue;
53 jsr166 1.22 import java.util.concurrent.CopyOnWriteArrayList;
54 jsr166 1.2 import java.util.concurrent.CountDownLatch;
55 jsr166 1.1 import java.util.concurrent.LinkedBlockingDeque;
56     import java.util.concurrent.LinkedBlockingQueue;
57     import java.util.concurrent.LinkedTransferQueue;
58 jsr166 1.2 import java.util.concurrent.PriorityBlockingQueue;
59 jsr166 1.1 import java.util.concurrent.ThreadLocalRandom;
60     import java.util.concurrent.TimeUnit;
61     import java.util.regex.Pattern;
62 jsr166 1.22 import java.util.stream.Stream;
63 jsr166 1.1
64     /**
65     * Usage: [iterations=N] [size=N] [filter=REGEXP] [warmup=SECONDS]
66     *
67     * To run this in micro-benchmark mode, simply run as a normal java program.
68     * Be patient; this program runs for a very long time.
69     * For faster runs, restrict execution using command line args.
70     *
71     * @author Martin Buchholz
72     */
73     public class RemoveMicroBenchmark {
74     abstract static class Job {
75     private final String name;
76     public Job(String name) { this.name = name; }
77     public String name() { return name; }
78     public abstract void work() throws Throwable;
79 jsr166 1.21 public void run() {
80     try { work(); }
81     catch (Throwable ex) {
82     // current job cannot always be deduced from stacktrace.
83     throw new RuntimeException("Job failed: " + name(), ex);
84     }
85     }
86 jsr166 1.1 }
87    
88 jsr166 1.5 final int iterations;
89     final int size; // number of elements in collections
90     final double warmupSeconds;
91     final long warmupNanos;
92 jsr166 1.22 final Pattern nameFilter; // select subset of Jobs to run
93 jsr166 1.5 final boolean reverse; // reverse order of Jobs
94     final boolean shuffle; // randomize order of Jobs
95    
96 jsr166 1.22 final ArrayList<Integer> elements; // contains size random Integers
97    
98 jsr166 1.5 RemoveMicroBenchmark(String[] args) {
99     iterations = intArg(args, "iterations", 10_000);
100     size = intArg(args, "size", 1000);
101     warmupSeconds = doubleArg(args, "warmup", 7.0);
102 jsr166 1.22 nameFilter = patternArg(args, "filter");
103 jsr166 1.5 reverse = booleanArg(args, "reverse");
104     shuffle = booleanArg(args, "shuffle");
105    
106     warmupNanos = (long) (warmupSeconds * (1000L * 1000L * 1000L));
107 jsr166 1.22
108     elements = ThreadLocalRandom.current().ints(size)
109     .mapToObj(x -> x)
110     .collect(toCollection(ArrayList::new));
111 jsr166 1.5 }
112 jsr166 1.1
113     // --------------- GC finalization infrastructure ---------------
114    
115     /** No guarantees, but effective in practice. */
116     static void forceFullGc() {
117 jsr166 1.24 long timeoutMillis = 1000L;
118     CountDownLatch finalized = new CountDownLatch(1);
119     ReferenceQueue<Object> queue = new ReferenceQueue<>();
120     WeakReference<Object> ref = new WeakReference<>(
121     new Object() { protected void finalize() { finalized.countDown(); }},
122     queue);
123 jsr166 1.1 try {
124 jsr166 1.24 for (int tries = 3; tries--> 0; ) {
125 jsr166 1.1 System.gc();
126 jsr166 1.24 if (finalized.await(timeoutMillis, MILLISECONDS)
127     && queue.remove(timeoutMillis) != null
128     && ref.get() == null) {
129 jsr166 1.1 System.runFinalization(); // try to pick up stragglers
130     return;
131     }
132 jsr166 1.24 timeoutMillis *= 4;
133 jsr166 1.1 }
134     } catch (InterruptedException unexpected) {
135     throw new AssertionError("unexpected InterruptedException");
136     }
137     throw new AssertionError("failed to do a \"full\" gc");
138     }
139    
140     /**
141     * Runs each job for long enough that all the runtime compilers
142     * have had plenty of time to warm up, i.e. get around to
143     * compiling everything worth compiling.
144     * Returns array of average times per job per run.
145     */
146 jsr166 1.21 long[] time0(List<Job> jobs) {
147 jsr166 1.1 final int size = jobs.size();
148     long[] nanoss = new long[size];
149     for (int i = 0; i < size; i++) {
150     if (warmupNanos > 0) forceFullGc();
151 jsr166 1.4 Job job = jobs.get(i);
152     long totalTime;
153     int runs = 0;
154     long startTime = System.nanoTime();
155 jsr166 1.21 do { job.run(); runs++; }
156 jsr166 1.4 while ((totalTime = System.nanoTime() - startTime) < warmupNanos);
157     nanoss[i] = totalTime/runs;
158 jsr166 1.1 }
159     return nanoss;
160     }
161    
162     void time(List<Job> jobs) throws Throwable {
163 jsr166 1.4 if (warmupNanos > 0) time0(jobs); // Warm up run
164 jsr166 1.1 final int size = jobs.size();
165     final long[] nanoss = time0(jobs); // Real timing run
166     final long[] milliss = new long[size];
167     final double[] ratios = new double[size];
168    
169     final String nameHeader = "Method";
170     final String millisHeader = "Millis";
171     final String ratioHeader = "Ratio";
172    
173     int nameWidth = nameHeader.length();
174     int millisWidth = millisHeader.length();
175     int ratioWidth = ratioHeader.length();
176    
177     for (int i = 0; i < size; i++) {
178     nameWidth = Math.max(nameWidth, jobs.get(i).name().length());
179    
180     milliss[i] = nanoss[i]/(1000L * 1000L);
181     millisWidth = Math.max(millisWidth,
182     String.format("%d", milliss[i]).length());
183    
184     ratios[i] = (double) nanoss[i] / (double) nanoss[0];
185     ratioWidth = Math.max(ratioWidth,
186     String.format("%.3f", ratios[i]).length());
187     }
188    
189     String format = String.format("%%-%ds %%%dd %%%d.3f%%n",
190     nameWidth, millisWidth, ratioWidth);
191     String headerFormat = String.format("%%-%ds %%%ds %%%ds%%n",
192     nameWidth, millisWidth, ratioWidth);
193     System.out.printf(headerFormat, "Method", "Millis", "Ratio");
194    
195     // Print out absolute and relative times, calibrated against first job
196     for (int i = 0; i < size; i++)
197     System.out.printf(format, jobs.get(i).name(), milliss[i], ratios[i]);
198     }
199    
200     private static String keywordValue(String[] args, String keyword) {
201     for (String arg : args)
202     if (arg.startsWith(keyword))
203     return arg.substring(keyword.length() + 1);
204     return null;
205     }
206    
207     private static int intArg(String[] args, String keyword, int defaultValue) {
208     String val = keywordValue(args, keyword);
209     return (val == null) ? defaultValue : Integer.parseInt(val);
210     }
211    
212     private static double doubleArg(String[] args, String keyword, double defaultValue) {
213     String val = keywordValue(args, keyword);
214     return (val == null) ? defaultValue : Double.parseDouble(val);
215     }
216    
217     private static Pattern patternArg(String[] args, String keyword) {
218     String val = keywordValue(args, keyword);
219     return (val == null) ? null : Pattern.compile(val);
220     }
221    
222 jsr166 1.5 private static boolean booleanArg(String[] args, String keyword) {
223     String val = keywordValue(args, keyword);
224     if (val == null || val.equals("false")) return false;
225     if (val.equals("true")) return true;
226     throw new IllegalArgumentException(val);
227     }
228    
229 jsr166 1.1 private static void deoptimize(int sum) {
230     if (sum == 42)
231     System.out.println("the answer");
232     }
233    
234     private static <T> Iterable<T> backwards(final List<T> list) {
235     return new Iterable<T>() {
236     public Iterator<T> iterator() {
237     return new Iterator<T>() {
238     final ListIterator<T> it = list.listIterator(list.size());
239     public boolean hasNext() { return it.hasPrevious(); }
240     public T next() { return it.previous(); }
241     public void remove() { it.remove(); }};}};
242     }
243    
244     // Checks for correctness *and* prevents loop optimizations
245 jsr166 1.18 static class Check {
246 jsr166 1.1 private int sum;
247     public void sum(int sum) {
248     if (this.sum == 0)
249     this.sum = sum;
250     if (this.sum != sum)
251     throw new AssertionError("Sum mismatch");
252     }
253     }
254     volatile Check check = new Check();
255    
256     public static void main(String[] args) throws Throwable {
257 jsr166 1.5 new RemoveMicroBenchmark(args).run();
258 jsr166 1.1 }
259    
260 jsr166 1.22 HashMap<Class<?>, String> goodClassName = new HashMap<>();
261 jsr166 1.1
262 jsr166 1.22 String goodClassName(Class<?> klazz) {
263     return goodClassName.computeIfAbsent(
264     klazz,
265     k -> {
266     String simple = k.getSimpleName();
267     return (simple.equals("SubList")) // too simple!
268     ? k.getName().replaceFirst(".*\\.", "")
269     : simple;
270     });
271     }
272 jsr166 1.1
273 jsr166 1.26 String goodClassName(Object x) {
274     return goodClassName(x.getClass());
275     }
276    
277 jsr166 1.22 static List<Integer> makeSubList(List<Integer> list) {
278 jsr166 1.1 final ThreadLocalRandom rnd = ThreadLocalRandom.current();
279 jsr166 1.22 int size = rnd.nextInt(4);
280     for (int i = size; i--> 0; )
281     list.add(rnd.nextInt());
282     int index = rnd.nextInt(size + 1);
283     return list.subList(index, index);
284     }
285    
286     private static <T> List<T> asSubList(List<T> list) {
287     return list.subList(0, list.size());
288     }
289    
290     @SafeVarargs @SuppressWarnings("varargs")
291 jsr166 1.25 private static <T> Stream<T> concatStreams(Stream<T> ... streams) {
292 jsr166 1.22 return Stream.of(streams).flatMap(s -> s);
293     }
294 jsr166 1.1
295 jsr166 1.22 Class<?> topLevelClass(Object x) {
296     for (Class<?> k = x.getClass();; ) {
297     Class<?> enclosing = k.getEnclosingClass();
298     if (enclosing == null)
299     return k;
300     k = enclosing;
301     }
302     }
303 jsr166 1.1
304 jsr166 1.22 void run() throws Throwable {
305     ArrayList<Job> jobs = Stream.<Collection<Integer>>of(
306     new ArrayList<>(),
307     makeSubList(new ArrayList<>()),
308     new LinkedList<>(),
309     makeSubList(new LinkedList<>()),
310     new Vector<>(),
311     makeSubList(new Vector<>()),
312     new CopyOnWriteArrayList<>(),
313     makeSubList(new CopyOnWriteArrayList<>()),
314     new ArrayDeque<>(),
315     new PriorityQueue<>(),
316     new ArrayBlockingQueue<>(elements.size()),
317     new ConcurrentLinkedQueue<>(),
318     new ConcurrentLinkedDeque<>(),
319     new LinkedBlockingQueue<>(),
320     new LinkedBlockingDeque<>(),
321     new LinkedTransferQueue<>(),
322     new PriorityBlockingQueue<>())
323     .flatMap(x -> jobs(x))
324     .filter(job ->
325     nameFilter == null || nameFilter.matcher(job.name()).find())
326     .collect(toCollection(ArrayList::new));
327 jsr166 1.1
328 jsr166 1.5 if (reverse) Collections.reverse(jobs);
329     if (shuffle) Collections.shuffle(jobs);
330    
331 jsr166 1.22 time(jobs);
332     }
333    
334     Stream<Job> jobs(Collection<Integer> x) {
335     return concatStreams(
336     collectionJobs(x),
337    
338     (CopyOnWriteArrayList.class.isAssignableFrom(topLevelClass(x)))
339     ? Stream.empty()
340     : iteratorRemoveJobs(x),
341    
342     (x instanceof Queue)
343     ? queueJobs((Queue<Integer>)x)
344     : Stream.empty(),
345    
346     (x instanceof Deque)
347     ? dequeJobs((Deque<Integer>)x)
348     : Stream.empty(),
349    
350     (x instanceof BlockingQueue)
351     ? blockingQueueJobs((BlockingQueue<Integer>)x)
352     : Stream.empty(),
353    
354     (x instanceof BlockingDeque)
355     ? blockingDequeJobs((BlockingDeque<Integer>)x)
356     : Stream.empty());
357 jsr166 1.1 }
358    
359     Collection<Integer> universeRecorder(int[] sum) {
360     return new ArrayList<>() {
361     public boolean contains(Object x) {
362     sum[0] += (Integer) x;
363     return true;
364     }};
365     }
366    
367     Collection<Integer> emptyRecorder(int[] sum) {
368     return new ArrayList<>() {
369     public boolean contains(Object x) {
370     sum[0] += (Integer) x;
371     return false;
372     }};
373     }
374    
375 jsr166 1.22 Stream<Job> collectionJobs(Collection<Integer> x) {
376 jsr166 1.26 final String klazz = goodClassName(x);
377 jsr166 1.22 return Stream.of(
378     new Job(klazz + " removeIf") {
379 jsr166 1.1 public void work() throws Throwable {
380     int[] sum = new int[1];
381     for (int i = 0; i < iterations; i++) {
382     sum[0] = 0;
383 jsr166 1.22 x.addAll(elements);
384 jsr166 1.1 x.removeIf(n -> { sum[0] += n; return true; });
385     check.sum(sum[0]);}}},
386 jsr166 1.22 new Job(klazz + " removeIf rnd-two-pass") {
387 jsr166 1.9 public void work() throws Throwable {
388     ThreadLocalRandom rnd = ThreadLocalRandom.current();
389     int[] sum = new int[1];
390     for (int i = 0; i < iterations; i++) {
391     sum[0] = 0;
392 jsr166 1.22 x.addAll(elements);
393 jsr166 1.9 x.removeIf(n -> {
394     boolean b = rnd.nextBoolean();
395     if (b) sum[0] += n;
396     return b; });
397     x.removeIf(n -> { sum[0] += n; return true; });
398     check.sum(sum[0]);}}},
399 jsr166 1.22 new Job(klazz + " removeAll") {
400 jsr166 1.1 public void work() throws Throwable {
401     int[] sum = new int[1];
402     Collection<Integer> universe = universeRecorder(sum);
403     for (int i = 0; i < iterations; i++) {
404     sum[0] = 0;
405 jsr166 1.22 x.addAll(elements);
406 jsr166 1.1 x.removeAll(universe);
407     check.sum(sum[0]);}}},
408 jsr166 1.22 new Job(klazz + " retainAll") {
409 jsr166 1.1 public void work() throws Throwable {
410     int[] sum = new int[1];
411     Collection<Integer> empty = emptyRecorder(sum);
412     for (int i = 0; i < iterations; i++) {
413     sum[0] = 0;
414 jsr166 1.22 x.addAll(elements);
415 jsr166 1.1 x.retainAll(empty);
416     check.sum(sum[0]);}}},
417 jsr166 1.22 new Job(klazz + " clear") {
418     public void work() throws Throwable {
419     int[] sum = new int[1];
420     for (int i = 0; i < iterations; i++) {
421     sum[0] = 0;
422     x.addAll(elements);
423     x.forEach(e -> sum[0] += e);
424     x.clear();
425     check.sum(sum[0]);}}});
426     }
427    
428     Stream<Job> iteratorRemoveJobs(Collection<Integer> x) {
429 jsr166 1.26 final String klazz = goodClassName(x);
430 jsr166 1.22 return Stream.of(
431     new Job(klazz + " Iterator.remove") {
432 jsr166 1.1 public void work() throws Throwable {
433     int[] sum = new int[1];
434     for (int i = 0; i < iterations; i++) {
435     sum[0] = 0;
436 jsr166 1.22 x.addAll(elements);
437 jsr166 1.1 Iterator<Integer> it = x.iterator();
438     while (it.hasNext()) {
439     sum[0] += it.next();
440     it.remove();
441     }
442     check.sum(sum[0]);}}},
443 jsr166 1.22 new Job(klazz + " Iterator.remove-rnd-two-pass") {
444 jsr166 1.10 public void work() throws Throwable {
445     ThreadLocalRandom rnd = ThreadLocalRandom.current();
446     int[] sum = new int[1];
447     for (int i = 0; i < iterations; i++) {
448     sum[0] = 0;
449 jsr166 1.22 x.addAll(elements);
450 jsr166 1.12 for (Iterator<Integer> it = x.iterator();
451     it.hasNext(); ) {
452     Integer e = it.next();
453 jsr166 1.10 if (rnd.nextBoolean()) {
454 jsr166 1.12 sum[0] += e;
455 jsr166 1.10 it.remove();
456     }
457     }
458 jsr166 1.12 for (Iterator<Integer> it = x.iterator();
459     it.hasNext(); ) {
460 jsr166 1.10 sum[0] += it.next();
461     it.remove();
462     }
463 jsr166 1.1 check.sum(sum[0]);}}});
464     }
465    
466 jsr166 1.22 Stream<Job> queueJobs(Queue<Integer> x) {
467 jsr166 1.26 final String klazz = goodClassName(x);
468 jsr166 1.22 return Stream.of(
469     new Job(klazz + " poll()") {
470 jsr166 1.8 public void work() throws Throwable {
471     int[] sum = new int[1];
472     for (int i = 0; i < iterations; i++) {
473     sum[0] = 0;
474 jsr166 1.22 x.addAll(elements);
475 jsr166 1.8 for (Integer e; (e = x.poll()) != null; )
476     sum[0] += e;
477     check.sum(sum[0]);}}});
478     }
479    
480 jsr166 1.22 Stream<Job> dequeJobs(Deque<Integer> x) {
481 jsr166 1.26 final String klazz = goodClassName(x);
482 jsr166 1.22 return Stream.of(
483     new Job(klazz + " descendingIterator().remove") {
484 jsr166 1.1 public void work() throws Throwable {
485     int[] sum = new int[1];
486     for (int i = 0; i < iterations; i++) {
487     sum[0] = 0;
488 jsr166 1.22 x.addAll(elements);
489 jsr166 1.1 Iterator<Integer> it = x.descendingIterator();
490     while (it.hasNext()) {
491     sum[0] += it.next();
492     it.remove();
493     }
494 jsr166 1.6 check.sum(sum[0]);}}},
495 jsr166 1.22 new Job(klazz + " pollFirst()") {
496 jsr166 1.6 public void work() throws Throwable {
497     int[] sum = new int[1];
498     for (int i = 0; i < iterations; i++) {
499     sum[0] = 0;
500 jsr166 1.22 x.addAll(elements);
501 jsr166 1.6 for (Integer e; (e = x.pollFirst()) != null; )
502     sum[0] += e;
503     check.sum(sum[0]);}}},
504 jsr166 1.22 new Job(klazz + " pollLast()") {
505 jsr166 1.6 public void work() throws Throwable {
506     int[] sum = new int[1];
507     for (int i = 0; i < iterations; i++) {
508     sum[0] = 0;
509 jsr166 1.22 x.addAll(elements);
510 jsr166 1.6 for (Integer e; (e = x.pollLast()) != null; )
511     sum[0] += e;
512 jsr166 1.1 check.sum(sum[0]);}}});
513     }
514 jsr166 1.3
515 jsr166 1.22 Stream<Job> blockingQueueJobs(BlockingQueue<Integer> x) {
516 jsr166 1.26 final String klazz = goodClassName(x);
517 jsr166 1.22 return Stream.of(
518 jsr166 1.23 new Job(klazz + " timed poll()") {
519     public void work() throws Throwable {
520     int[] sum = new int[1];
521     for (int i = 0; i < iterations; i++) {
522     sum[0] = 0;
523     x.addAll(elements);
524     for (Integer e; (e = x.poll(0L, TimeUnit.DAYS)) != null; )
525     sum[0] += e;
526     check.sum(sum[0]);}}},
527 jsr166 1.22 new Job(klazz + " drainTo(sink)") {
528 jsr166 1.3 public void work() throws Throwable {
529     ArrayList<Integer> sink = new ArrayList<>();
530     int[] sum = new int[1];
531     for (int i = 0; i < iterations; i++) {
532     sum[0] = 0;
533     sink.clear();
534 jsr166 1.22 x.addAll(elements);
535 jsr166 1.3 x.drainTo(sink);
536     sink.forEach(e -> sum[0] += e);
537     check.sum(sum[0]);}}},
538 jsr166 1.22 new Job(klazz + " drainTo(sink, n)") {
539 jsr166 1.3 public void work() throws Throwable {
540     ArrayList<Integer> sink = new ArrayList<>();
541     int[] sum = new int[1];
542     for (int i = 0; i < iterations; i++) {
543     sum[0] = 0;
544     sink.clear();
545 jsr166 1.22 x.addAll(elements);
546     x.drainTo(sink, elements.size());
547 jsr166 1.3 sink.forEach(e -> sum[0] += e);
548     check.sum(sum[0]);}}});
549     }
550 jsr166 1.7
551 jsr166 1.22 Stream<Job> blockingDequeJobs(BlockingDeque<Integer> x) {
552 jsr166 1.26 final String klazz = goodClassName(x);
553 jsr166 1.22 return Stream.of(
554     new Job(klazz + " timed pollFirst()") {
555 jsr166 1.7 public void work() throws Throwable {
556     int[] sum = new int[1];
557     for (int i = 0; i < iterations; i++) {
558     sum[0] = 0;
559 jsr166 1.22 x.addAll(elements);
560 jsr166 1.7 for (Integer e; (e = x.pollFirst(0L, TimeUnit.DAYS)) != null; )
561     sum[0] += e;
562     check.sum(sum[0]);}}},
563 jsr166 1.22 new Job(klazz + " timed pollLast()") {
564 jsr166 1.7 public void work() throws Throwable {
565     int[] sum = new int[1];
566     for (int i = 0; i < iterations; i++) {
567     sum[0] = 0;
568 jsr166 1.22 x.addAll(elements);
569 jsr166 1.7 for (Integer e; (e = x.pollLast(0L, TimeUnit.DAYS)) != null; )
570     sum[0] += e;
571     check.sum(sum[0]);}}});
572     }
573 jsr166 1.1 }