ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Collection/IteratorMicroBenchmark.java
(Generate patch)

Comparing jsr166/src/test/jtreg/util/Collection/IteratorMicroBenchmark.java (file contents):
Revision 1.29 by jsr166, Sun Jan 7 21:11:41 2018 UTC vs.
Revision 1.30 by jsr166, Sat Jan 27 18:39:28 2018 UTC

# Line 46 | Line 46 | import java.util.Vector;
46   import java.util.concurrent.ArrayBlockingQueue;
47   import java.util.concurrent.ConcurrentLinkedDeque;
48   import java.util.concurrent.ConcurrentLinkedQueue;
49 + import java.util.concurrent.CopyOnWriteArrayList;
50   import java.util.concurrent.LinkedBlockingDeque;
51   import java.util.concurrent.LinkedBlockingQueue;
52   import java.util.concurrent.LinkedTransferQueue;
# Line 55 | Line 56 | import java.util.concurrent.ThreadLocalR
56   import java.util.concurrent.TimeUnit;
57   import java.util.concurrent.atomic.LongAdder;
58   import java.util.regex.Pattern;
59 + import java.util.stream.Stream;
60  
61   /**
62   * Usage: [iterations=N] [size=N] [filter=REGEXP] [warmup=SECONDS]
# Line 270 | Line 272 | public class IteratorMicroBenchmark {
272  
273          ArrayList<Job> jobs = new ArrayList<>();
274  
275 <        List.<Collection<Integer>>of(
275 >        Stream.<Collection<Integer>>of(
276              al, ad, abq,
277              new LinkedList<>(al),
278              new PriorityQueue<>(al),
279              new Vector<>(al),
280 +            new CopyOnWriteArrayList<>(al),
281              new ConcurrentLinkedQueue<>(al),
282              new ConcurrentLinkedDeque<>(al),
283              new LinkedBlockingQueue<>(al),
284              new LinkedBlockingDeque<>(al),
285              new LinkedTransferQueue<>(al),
286 <            new PriorityBlockingQueue<>(al)).forEach(
287 <                x -> {
288 <                    jobs.addAll(collectionJobs(x));
289 <                    if (x instanceof Deque)
290 <                        jobs.addAll(dequeJobs((Deque<Integer>)x));
291 <                });
286 >            new PriorityBlockingQueue<>(al))
287 >            .forEach(x -> {
288 >                jobs.addAll(collectionJobs(x));
289 >                if (x instanceof Deque)
290 >                    jobs.addAll(dequeJobs((Deque<Integer>)x));
291 >                if (x instanceof List)
292 >                    jobs.addAll(listJobs((List<Integer>)x));
293 >            });
294  
295          if (reverse) Collections.reverse(jobs);
296          if (shuffle) Collections.shuffle(jobs);
# Line 455 | Line 460 | public class IteratorMicroBenchmark {
460                          x.descendingIterator().forEachRemaining(n -> sum[0] += n);
461                          check.sum(sum[0]);}}});
462      }
463 +
464 +    List<Job> listJobs(List<Integer> x) {
465 +        String klazz = x.getClass().getSimpleName();
466 +        return List.of(
467 +            new Job(klazz + " subList toArray()") {
468 +                public void work() throws Throwable {
469 +                    int size = x.size();
470 +                    for (int i = 0; i < iterations; i++) {
471 +                        int total = Stream.of(x.subList(0, size / 2),
472 +                                              x.subList(size / 2, size))
473 +                            .mapToInt(subList -> {
474 +                                int sum = 0;
475 +                                for (Object o : subList.toArray())
476 +                                    sum += (Integer) o;
477 +                                return sum; })
478 +                            .sum();
479 +                        check.sum(total);}}},
480 +            new Job(klazz + " subList toArray(a)") {
481 +                public void work() throws Throwable {
482 +                    int size = x.size();
483 +                    for (int i = 0; i < iterations; i++) {
484 +                        int total = Stream.of(x.subList(0, size / 2),
485 +                                              x.subList(size / 2, size))
486 +                            .mapToInt(subList -> {
487 +                                int sum = 0;
488 +                                Integer[] a = new Integer[subList.size()];
489 +                                for (Object o : subList.toArray(a))
490 +                                    sum += (Integer) o;
491 +                                return sum; })
492 +                            .sum();
493 +                        check.sum(total);}}},
494 +            new Job(klazz + " subList toArray(empty)") {
495 +                public void work() throws Throwable {
496 +                    int size = x.size();
497 +                    Integer[] empty = new Integer[0];
498 +                    for (int i = 0; i < iterations; i++) {
499 +                        int total = Stream.of(x.subList(0, size / 2),
500 +                                              x.subList(size / 2, size))
501 +                            .mapToInt(subList -> {
502 +                                int sum = 0;
503 +                                for (Object o : subList.toArray(empty))
504 +                                    sum += (Integer) o;
505 +                                return sum; })
506 +                            .sum();
507 +                        check.sum(total);}}});
508 +    }
509   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines