42319
|
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 |
import java.lang.ref.WeakReference;
|
|
31 |
import java.util.ArrayDeque;
|
|
32 |
import java.util.Arrays;
|
|
33 |
import java.util.ArrayList;
|
|
34 |
import java.util.Collection;
|
|
35 |
import java.util.Collections;
|
|
36 |
import java.util.Deque;
|
|
37 |
import java.util.Enumeration;
|
|
38 |
import java.util.Iterator;
|
|
39 |
import java.util.LinkedList;
|
|
40 |
import java.util.List;
|
|
41 |
import java.util.ListIterator;
|
|
42 |
import java.util.Map;
|
|
43 |
import java.util.PriorityQueue;
|
|
44 |
import java.util.Queue;
|
|
45 |
import java.util.Spliterator;
|
|
46 |
import java.util.Vector;
|
|
47 |
import java.util.concurrent.ArrayBlockingQueue;
|
|
48 |
import java.util.concurrent.BlockingDeque;
|
|
49 |
import java.util.concurrent.BlockingQueue;
|
|
50 |
import java.util.concurrent.ConcurrentLinkedDeque;
|
|
51 |
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
52 |
import java.util.concurrent.CountDownLatch;
|
|
53 |
import java.util.concurrent.LinkedBlockingDeque;
|
|
54 |
import java.util.concurrent.LinkedBlockingQueue;
|
|
55 |
import java.util.concurrent.LinkedTransferQueue;
|
|
56 |
import java.util.concurrent.PriorityBlockingQueue;
|
|
57 |
import java.util.concurrent.ThreadLocalRandom;
|
|
58 |
import java.util.concurrent.TimeUnit;
|
|
59 |
import java.util.regex.Pattern;
|
|
60 |
import java.util.function.Supplier;
|
|
61 |
|
|
62 |
/**
|
|
63 |
* Usage: [iterations=N] [size=N] [filter=REGEXP] [warmup=SECONDS]
|
|
64 |
*
|
|
65 |
* To run this in micro-benchmark mode, simply run as a normal java program.
|
|
66 |
* Be patient; this program runs for a very long time.
|
|
67 |
* For faster runs, restrict execution using command line args.
|
|
68 |
*
|
|
69 |
* @author Martin Buchholz
|
|
70 |
*/
|
|
71 |
public class RemoveMicroBenchmark {
|
|
72 |
abstract static class Job {
|
|
73 |
private final String name;
|
|
74 |
public Job(String name) { this.name = name; }
|
|
75 |
public String name() { return name; }
|
|
76 |
public abstract void work() throws Throwable;
|
|
77 |
}
|
|
78 |
|
|
79 |
final int iterations;
|
|
80 |
final int size; // number of elements in collections
|
|
81 |
final double warmupSeconds;
|
|
82 |
final long warmupNanos;
|
|
83 |
final Pattern filter; // select subset of Jobs to run
|
|
84 |
final boolean reverse; // reverse order of Jobs
|
|
85 |
final boolean shuffle; // randomize order of Jobs
|
|
86 |
|
|
87 |
RemoveMicroBenchmark(String[] args) {
|
|
88 |
iterations = intArg(args, "iterations", 10_000);
|
|
89 |
size = intArg(args, "size", 1000);
|
|
90 |
warmupSeconds = doubleArg(args, "warmup", 7.0);
|
|
91 |
filter = patternArg(args, "filter");
|
|
92 |
reverse = booleanArg(args, "reverse");
|
|
93 |
shuffle = booleanArg(args, "shuffle");
|
|
94 |
|
|
95 |
warmupNanos = (long) (warmupSeconds * (1000L * 1000L * 1000L));
|
|
96 |
}
|
|
97 |
|
|
98 |
// --------------- GC finalization infrastructure ---------------
|
|
99 |
|
|
100 |
/** No guarantees, but effective in practice. */
|
|
101 |
static void forceFullGc() {
|
|
102 |
CountDownLatch finalizeDone = new CountDownLatch(1);
|
|
103 |
WeakReference<?> ref = new WeakReference<Object>(new Object() {
|
|
104 |
protected void finalize() { finalizeDone.countDown(); }});
|
|
105 |
try {
|
|
106 |
for (int i = 0; i < 10; i++) {
|
|
107 |
System.gc();
|
|
108 |
if (finalizeDone.await(1L, TimeUnit.SECONDS) && ref.get() == null) {
|
|
109 |
System.runFinalization(); // try to pick up stragglers
|
|
110 |
return;
|
|
111 |
}
|
|
112 |
}
|
|
113 |
} catch (InterruptedException unexpected) {
|
|
114 |
throw new AssertionError("unexpected InterruptedException");
|
|
115 |
}
|
|
116 |
throw new AssertionError("failed to do a \"full\" gc");
|
|
117 |
}
|
|
118 |
|
|
119 |
/**
|
|
120 |
* Runs each job for long enough that all the runtime compilers
|
|
121 |
* have had plenty of time to warm up, i.e. get around to
|
|
122 |
* compiling everything worth compiling.
|
|
123 |
* Returns array of average times per job per run.
|
|
124 |
*/
|
|
125 |
long[] time0(List<Job> jobs) throws Throwable {
|
|
126 |
final int size = jobs.size();
|
|
127 |
long[] nanoss = new long[size];
|
|
128 |
for (int i = 0; i < size; i++) {
|
|
129 |
if (warmupNanos > 0) forceFullGc();
|
|
130 |
Job job = jobs.get(i);
|
|
131 |
long totalTime;
|
|
132 |
int runs = 0;
|
|
133 |
long startTime = System.nanoTime();
|
|
134 |
do { job.work(); runs++; }
|
|
135 |
while ((totalTime = System.nanoTime() - startTime) < warmupNanos);
|
|
136 |
nanoss[i] = totalTime/runs;
|
|
137 |
}
|
|
138 |
return nanoss;
|
|
139 |
}
|
|
140 |
|
|
141 |
void time(List<Job> jobs) throws Throwable {
|
|
142 |
if (warmupNanos > 0) time0(jobs); // Warm up run
|
|
143 |
final int size = jobs.size();
|
|
144 |
final long[] nanoss = time0(jobs); // Real timing run
|
|
145 |
final long[] milliss = new long[size];
|
|
146 |
final double[] ratios = new double[size];
|
|
147 |
|
|
148 |
final String nameHeader = "Method";
|
|
149 |
final String millisHeader = "Millis";
|
|
150 |
final String ratioHeader = "Ratio";
|
|
151 |
|
|
152 |
int nameWidth = nameHeader.length();
|
|
153 |
int millisWidth = millisHeader.length();
|
|
154 |
int ratioWidth = ratioHeader.length();
|
|
155 |
|
|
156 |
for (int i = 0; i < size; i++) {
|
|
157 |
nameWidth = Math.max(nameWidth, jobs.get(i).name().length());
|
|
158 |
|
|
159 |
milliss[i] = nanoss[i]/(1000L * 1000L);
|
|
160 |
millisWidth = Math.max(millisWidth,
|
|
161 |
String.format("%d", milliss[i]).length());
|
|
162 |
|
|
163 |
ratios[i] = (double) nanoss[i] / (double) nanoss[0];
|
|
164 |
ratioWidth = Math.max(ratioWidth,
|
|
165 |
String.format("%.3f", ratios[i]).length());
|
|
166 |
}
|
|
167 |
|
|
168 |
String format = String.format("%%-%ds %%%dd %%%d.3f%%n",
|
|
169 |
nameWidth, millisWidth, ratioWidth);
|
|
170 |
String headerFormat = String.format("%%-%ds %%%ds %%%ds%%n",
|
|
171 |
nameWidth, millisWidth, ratioWidth);
|
|
172 |
System.out.printf(headerFormat, "Method", "Millis", "Ratio");
|
|
173 |
|
|
174 |
// Print out absolute and relative times, calibrated against first job
|
|
175 |
for (int i = 0; i < size; i++)
|
|
176 |
System.out.printf(format, jobs.get(i).name(), milliss[i], ratios[i]);
|
|
177 |
}
|
|
178 |
|
|
179 |
private static String keywordValue(String[] args, String keyword) {
|
|
180 |
for (String arg : args)
|
|
181 |
if (arg.startsWith(keyword))
|
|
182 |
return arg.substring(keyword.length() + 1);
|
|
183 |
return null;
|
|
184 |
}
|
|
185 |
|
|
186 |
private static int intArg(String[] args, String keyword, int defaultValue) {
|
|
187 |
String val = keywordValue(args, keyword);
|
|
188 |
return (val == null) ? defaultValue : Integer.parseInt(val);
|
|
189 |
}
|
|
190 |
|
|
191 |
private static double doubleArg(String[] args, String keyword, double defaultValue) {
|
|
192 |
String val = keywordValue(args, keyword);
|
|
193 |
return (val == null) ? defaultValue : Double.parseDouble(val);
|
|
194 |
}
|
|
195 |
|
|
196 |
private static Pattern patternArg(String[] args, String keyword) {
|
|
197 |
String val = keywordValue(args, keyword);
|
|
198 |
return (val == null) ? null : Pattern.compile(val);
|
|
199 |
}
|
|
200 |
|
|
201 |
private static boolean booleanArg(String[] args, String keyword) {
|
|
202 |
String val = keywordValue(args, keyword);
|
|
203 |
if (val == null || val.equals("false")) return false;
|
|
204 |
if (val.equals("true")) return true;
|
|
205 |
throw new IllegalArgumentException(val);
|
|
206 |
}
|
|
207 |
|
|
208 |
private static List<Job> filter(Pattern filter, List<Job> jobs) {
|
|
209 |
if (filter == null) return jobs;
|
|
210 |
ArrayList<Job> newJobs = new ArrayList<>();
|
|
211 |
for (Job job : jobs)
|
|
212 |
if (filter.matcher(job.name()).find())
|
|
213 |
newJobs.add(job);
|
|
214 |
return newJobs;
|
|
215 |
}
|
|
216 |
|
|
217 |
private static void deoptimize(int sum) {
|
|
218 |
if (sum == 42)
|
|
219 |
System.out.println("the answer");
|
|
220 |
}
|
|
221 |
|
|
222 |
private static <T> List<T> asSubList(List<T> list) {
|
|
223 |
return list.subList(0, list.size());
|
|
224 |
}
|
|
225 |
|
|
226 |
private static <T> Iterable<T> backwards(final List<T> list) {
|
|
227 |
return new Iterable<T>() {
|
|
228 |
public Iterator<T> iterator() {
|
|
229 |
return new Iterator<T>() {
|
|
230 |
final ListIterator<T> it = list.listIterator(list.size());
|
|
231 |
public boolean hasNext() { return it.hasPrevious(); }
|
|
232 |
public T next() { return it.previous(); }
|
|
233 |
public void remove() { it.remove(); }};}};
|
|
234 |
}
|
|
235 |
|
|
236 |
// Checks for correctness *and* prevents loop optimizations
|
|
237 |
class Check {
|
|
238 |
private int sum;
|
|
239 |
public void sum(int sum) {
|
|
240 |
if (this.sum == 0)
|
|
241 |
this.sum = sum;
|
|
242 |
if (this.sum != sum)
|
|
243 |
throw new AssertionError("Sum mismatch");
|
|
244 |
}
|
|
245 |
}
|
|
246 |
volatile Check check = new Check();
|
|
247 |
|
|
248 |
public static void main(String[] args) throws Throwable {
|
|
249 |
new RemoveMicroBenchmark(args).run();
|
|
250 |
}
|
|
251 |
|
|
252 |
void run() throws Throwable {
|
|
253 |
// System.out.printf(
|
|
254 |
// "iterations=%d size=%d, warmup=%1g, filter=\"%s\"%n",
|
|
255 |
// iterations, size, warmupSeconds, filter);
|
|
256 |
|
|
257 |
final ArrayList<Integer> al = new ArrayList<Integer>(size);
|
|
258 |
|
|
259 |
// Populate collections with random data
|
|
260 |
final ThreadLocalRandom rnd = ThreadLocalRandom.current();
|
|
261 |
for (int i = 0; i < size; i++)
|
|
262 |
al.add(rnd.nextInt(size));
|
|
263 |
|
|
264 |
ArrayList<Job> jobs = new ArrayList<>();
|
|
265 |
|
|
266 |
List.<Collection<Integer>>of(
|
|
267 |
new ArrayList<>(),
|
|
268 |
new LinkedList<>(),
|
|
269 |
new Vector<>(),
|
|
270 |
new ArrayDeque<>(),
|
|
271 |
new PriorityQueue<>(),
|
|
272 |
new ArrayBlockingQueue<>(al.size()),
|
|
273 |
new ConcurrentLinkedQueue<>(),
|
|
274 |
new ConcurrentLinkedDeque<>(),
|
|
275 |
new LinkedBlockingQueue<>(),
|
|
276 |
new LinkedBlockingDeque<>(),
|
|
277 |
new LinkedTransferQueue<>(),
|
|
278 |
new PriorityBlockingQueue<>())
|
|
279 |
.stream().forEach(
|
|
280 |
x -> {
|
|
281 |
String klazz = x.getClass().getSimpleName();
|
|
282 |
jobs.addAll(collectionJobs(klazz, () -> x, al));
|
|
283 |
if (x instanceof Queue) {
|
|
284 |
Queue<Integer> queue = (Queue<Integer>) x;
|
|
285 |
jobs.addAll(queueJobs(klazz, () -> queue, al));
|
|
286 |
}
|
|
287 |
if (x instanceof Deque) {
|
|
288 |
Deque<Integer> deque = (Deque<Integer>) x;
|
|
289 |
jobs.addAll(dequeJobs(klazz, () -> deque, al));
|
|
290 |
}
|
|
291 |
if (x instanceof BlockingQueue) {
|
|
292 |
BlockingQueue<Integer> q = (BlockingQueue<Integer>) x;
|
|
293 |
jobs.addAll(blockingQueueJobs(klazz, () -> q, al));
|
|
294 |
}
|
|
295 |
if (x instanceof BlockingDeque) {
|
|
296 |
BlockingDeque<Integer> q = (BlockingDeque<Integer>) x;
|
|
297 |
jobs.addAll(blockingDequeJobs(klazz, () -> q, al));
|
|
298 |
}
|
|
299 |
if (x instanceof List) {
|
|
300 |
List<Integer> list = (List<Integer>) x;
|
|
301 |
jobs.addAll(
|
|
302 |
collectionJobs(
|
|
303 |
klazz + " subList",
|
|
304 |
() -> list.subList(0, x.size()),
|
|
305 |
al));
|
|
306 |
}
|
|
307 |
});
|
|
308 |
|
|
309 |
if (reverse) Collections.reverse(jobs);
|
|
310 |
if (shuffle) Collections.shuffle(jobs);
|
|
311 |
|
|
312 |
time(filter(filter, jobs));
|
|
313 |
}
|
|
314 |
|
|
315 |
Collection<Integer> universeRecorder(int[] sum) {
|
|
316 |
return new ArrayList<>() {
|
|
317 |
public boolean contains(Object x) {
|
|
318 |
sum[0] += (Integer) x;
|
|
319 |
return true;
|
|
320 |
}};
|
|
321 |
}
|
|
322 |
|
|
323 |
Collection<Integer> emptyRecorder(int[] sum) {
|
|
324 |
return new ArrayList<>() {
|
|
325 |
public boolean contains(Object x) {
|
|
326 |
sum[0] += (Integer) x;
|
|
327 |
return false;
|
|
328 |
}};
|
|
329 |
}
|
|
330 |
|
|
331 |
List<Job> collectionJobs(
|
|
332 |
String description,
|
|
333 |
Supplier<Collection<Integer>> supplier,
|
|
334 |
ArrayList<Integer> al) {
|
|
335 |
return List.of(
|
|
336 |
new Job(description + " .removeIf") {
|
|
337 |
public void work() throws Throwable {
|
|
338 |
Collection<Integer> x = supplier.get();
|
|
339 |
int[] sum = new int[1];
|
|
340 |
for (int i = 0; i < iterations; i++) {
|
|
341 |
sum[0] = 0;
|
|
342 |
x.addAll(al);
|
|
343 |
x.removeIf(n -> { sum[0] += n; return true; });
|
|
344 |
check.sum(sum[0]);}}},
|
|
345 |
new Job(description + " .removeAll") {
|
|
346 |
public void work() throws Throwable {
|
|
347 |
Collection<Integer> x = supplier.get();
|
|
348 |
int[] sum = new int[1];
|
|
349 |
Collection<Integer> universe = universeRecorder(sum);
|
|
350 |
for (int i = 0; i < iterations; i++) {
|
|
351 |
sum[0] = 0;
|
|
352 |
x.addAll(al);
|
|
353 |
x.removeAll(universe);
|
|
354 |
check.sum(sum[0]);}}},
|
|
355 |
new Job(description + " .retainAll") {
|
|
356 |
public void work() throws Throwable {
|
|
357 |
Collection<Integer> x = supplier.get();
|
|
358 |
int[] sum = new int[1];
|
|
359 |
Collection<Integer> empty = emptyRecorder(sum);
|
|
360 |
for (int i = 0; i < iterations; i++) {
|
|
361 |
sum[0] = 0;
|
|
362 |
x.addAll(al);
|
|
363 |
x.retainAll(empty);
|
|
364 |
check.sum(sum[0]);}}},
|
|
365 |
new Job(description + " Iterator.remove") {
|
|
366 |
public void work() throws Throwable {
|
|
367 |
Collection<Integer> x = supplier.get();
|
|
368 |
int[] sum = new int[1];
|
|
369 |
for (int i = 0; i < iterations; i++) {
|
|
370 |
sum[0] = 0;
|
|
371 |
x.addAll(al);
|
|
372 |
Iterator<Integer> it = x.iterator();
|
|
373 |
while (it.hasNext()) {
|
|
374 |
sum[0] += it.next();
|
|
375 |
it.remove();
|
|
376 |
}
|
|
377 |
check.sum(sum[0]);}}},
|
|
378 |
new Job(description + " clear") {
|
|
379 |
public void work() throws Throwable {
|
|
380 |
Collection<Integer> x = supplier.get();
|
|
381 |
int[] sum = new int[1];
|
|
382 |
for (int i = 0; i < iterations; i++) {
|
|
383 |
sum[0] = 0;
|
|
384 |
x.addAll(al);
|
|
385 |
x.forEach(e -> sum[0] += e);
|
|
386 |
x.clear();
|
|
387 |
check.sum(sum[0]);}}});
|
|
388 |
}
|
|
389 |
|
|
390 |
List<Job> queueJobs(
|
|
391 |
String description,
|
|
392 |
Supplier<Queue<Integer>> supplier,
|
|
393 |
ArrayList<Integer> al) {
|
|
394 |
return List.of(
|
|
395 |
new Job(description + " poll()") {
|
|
396 |
public void work() throws Throwable {
|
|
397 |
Queue<Integer> x = supplier.get();
|
|
398 |
int[] sum = new int[1];
|
|
399 |
for (int i = 0; i < iterations; i++) {
|
|
400 |
sum[0] = 0;
|
|
401 |
x.addAll(al);
|
|
402 |
for (Integer e; (e = x.poll()) != null; )
|
|
403 |
sum[0] += e;
|
|
404 |
check.sum(sum[0]);}}});
|
|
405 |
}
|
|
406 |
|
|
407 |
List<Job> dequeJobs(
|
|
408 |
String description,
|
|
409 |
Supplier<Deque<Integer>> supplier,
|
|
410 |
ArrayList<Integer> al) {
|
|
411 |
return List.of(
|
|
412 |
new Job(description + " descendingIterator().remove") {
|
|
413 |
public void work() throws Throwable {
|
|
414 |
Deque<Integer> x = supplier.get();
|
|
415 |
int[] sum = new int[1];
|
|
416 |
for (int i = 0; i < iterations; i++) {
|
|
417 |
sum[0] = 0;
|
|
418 |
x.addAll(al);
|
|
419 |
Iterator<Integer> it = x.descendingIterator();
|
|
420 |
while (it.hasNext()) {
|
|
421 |
sum[0] += it.next();
|
|
422 |
it.remove();
|
|
423 |
}
|
|
424 |
check.sum(sum[0]);}}},
|
|
425 |
new Job(description + " pollFirst()") {
|
|
426 |
public void work() throws Throwable {
|
|
427 |
Deque<Integer> x = supplier.get();
|
|
428 |
int[] sum = new int[1];
|
|
429 |
for (int i = 0; i < iterations; i++) {
|
|
430 |
sum[0] = 0;
|
|
431 |
x.addAll(al);
|
|
432 |
for (Integer e; (e = x.pollFirst()) != null; )
|
|
433 |
sum[0] += e;
|
|
434 |
check.sum(sum[0]);}}},
|
|
435 |
new Job(description + " pollLast()") {
|
|
436 |
public void work() throws Throwable {
|
|
437 |
Deque<Integer> x = supplier.get();
|
|
438 |
int[] sum = new int[1];
|
|
439 |
for (int i = 0; i < iterations; i++) {
|
|
440 |
sum[0] = 0;
|
|
441 |
x.addAll(al);
|
|
442 |
for (Integer e; (e = x.pollLast()) != null; )
|
|
443 |
sum[0] += e;
|
|
444 |
check.sum(sum[0]);}}});
|
|
445 |
}
|
|
446 |
|
|
447 |
List<Job> blockingQueueJobs(
|
|
448 |
String description,
|
|
449 |
Supplier<BlockingQueue<Integer>> supplier,
|
|
450 |
ArrayList<Integer> al) {
|
|
451 |
return List.of(
|
|
452 |
new Job(description + " drainTo(sink)") {
|
|
453 |
public void work() throws Throwable {
|
|
454 |
BlockingQueue<Integer> x = supplier.get();
|
|
455 |
ArrayList<Integer> sink = new ArrayList<>();
|
|
456 |
int[] sum = new int[1];
|
|
457 |
for (int i = 0; i < iterations; i++) {
|
|
458 |
sum[0] = 0;
|
|
459 |
sink.clear();
|
|
460 |
x.addAll(al);
|
|
461 |
x.drainTo(sink);
|
|
462 |
sink.forEach(e -> sum[0] += e);
|
|
463 |
check.sum(sum[0]);}}},
|
|
464 |
new Job(description + " drainTo(sink, n)") {
|
|
465 |
public void work() throws Throwable {
|
|
466 |
BlockingQueue<Integer> x = supplier.get();
|
|
467 |
ArrayList<Integer> sink = new ArrayList<>();
|
|
468 |
int[] sum = new int[1];
|
|
469 |
for (int i = 0; i < iterations; i++) {
|
|
470 |
sum[0] = 0;
|
|
471 |
sink.clear();
|
|
472 |
x.addAll(al);
|
|
473 |
x.drainTo(sink, al.size());
|
|
474 |
sink.forEach(e -> sum[0] += e);
|
|
475 |
check.sum(sum[0]);}}});
|
|
476 |
}
|
|
477 |
|
|
478 |
List<Job> blockingDequeJobs(
|
|
479 |
String description,
|
|
480 |
Supplier<BlockingDeque<Integer>> supplier,
|
|
481 |
ArrayList<Integer> al) {
|
|
482 |
return List.of(
|
|
483 |
new Job(description + " timed pollFirst()") {
|
|
484 |
public void work() throws Throwable {
|
|
485 |
BlockingDeque<Integer> x = supplier.get();
|
|
486 |
int[] sum = new int[1];
|
|
487 |
for (int i = 0; i < iterations; i++) {
|
|
488 |
sum[0] = 0;
|
|
489 |
x.addAll(al);
|
|
490 |
for (Integer e; (e = x.pollFirst(0L, TimeUnit.DAYS)) != null; )
|
|
491 |
sum[0] += e;
|
|
492 |
check.sum(sum[0]);}}},
|
|
493 |
new Job(description + " timed pollLast()") {
|
|
494 |
public void work() throws Throwable {
|
|
495 |
BlockingDeque<Integer> x = supplier.get();
|
|
496 |
int[] sum = new int[1];
|
|
497 |
for (int i = 0; i < iterations; i++) {
|
|
498 |
sum[0] = 0;
|
|
499 |
x.addAll(al);
|
|
500 |
for (Integer e; (e = x.pollLast(0L, TimeUnit.DAYS)) != null; )
|
|
501 |
sum[0] += e;
|
|
502 |
check.sum(sum[0]);}}});
|
|
503 |
}
|
|
504 |
}
|