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.47 by jsr166, Sun Jun 10 02:32:59 2018 UTC vs.
Revision 1.48 by jsr166, Wed Jan 2 16:39:09 2019 UTC

# Line 304 | Line 304 | public class IteratorMicroBenchmark {
304                  makeSubList(new LinkedList<>(al)),
305                  new PriorityQueue<>(al),
306                  new Vector<>(al),
307 +                List.of(al.toArray(new Integer[0])),
308                  makeSubList(new Vector<>(al)),
309                  new CopyOnWriteArrayList<>(al),
310                  makeSubList(new CopyOnWriteArrayList<>(al)),
# Line 329 | Line 330 | public class IteratorMicroBenchmark {
330          return Stream.of(streams).flatMap(s -> s);
331      }
332  
333 +    boolean isMutable(Collection<Integer> x) {
334 +        return !goodClassName(x.getClass()).equals("ListN");
335 +    }
336 +
337      Stream<Job> jobs(Collection<Integer> x) {
338 +        final String klazz = goodClassName(x.getClass());
339          return concatStreams(
340              collectionJobs(x),
341  
342 +            (isMutable(x))
343 +            ? mutableCollectionJobs(x)
344 +            : Stream.empty(),
345 +
346              (x instanceof Deque)
347              ? dequeJobs((Deque<Integer>)x)
348              : Stream.empty(),
349  
350              (x instanceof List)
351              ? listJobs((List<Integer>)x)
352 +            : Stream.empty(),
353 +
354 +            (x instanceof List && isMutable(x))
355 +            ? mutableListJobs((List<Integer>)x)
356              : Stream.empty());
357      }
358  
# Line 381 | Line 395 | public class IteratorMicroBenchmark {
395                          sum[0] = 0;
396                          x.spliterator().forEachRemaining(n -> sum[0] += n);
397                          check.sum(sum[0]);}}},
384            new Job(klazz + " removeIf") {
385                public void work() throws Throwable {
386                    int[] sum = new int[1];
387                    for (int i = 0; i < iterations; i++) {
388                        sum[0] = 0;
389                        if (x.removeIf(n -> { sum[0] += n; return false; }))
390                            throw new AssertionError();
391                        check.sum(sum[0]);}}},
398              new Job(klazz + " contains") {
399                  public void work() throws Throwable {
400                      int[] sum = new int[1];
# Line 407 | Line 413 | public class IteratorMicroBenchmark {
413                          if (x.containsAll(sneakyAdderCollection))
414                              throw new AssertionError();
415                          check.sum(sum[0]);}}},
410            new Job(klazz + " remove(Object)") {
411                public void work() throws Throwable {
412                    int[] sum = new int[1];
413                    Object sneakyAdder = sneakyAdder(sum);
414                    for (int i = 0; i < iterations; i++) {
415                        sum[0] = 0;
416                        if (x.remove(sneakyAdder)) throw new AssertionError();
417                        check.sum(sum[0]);}}},
416              new Job(klazz + " forEach") {
417                  public void work() throws Throwable {
418                      int[] sum = new int[1];
# Line 498 | Line 496 | public class IteratorMicroBenchmark {
496                          check.sum(sum[0]);}}});
497      }
498  
499 +    Stream<Job> mutableCollectionJobs(Collection<Integer> x) {
500 +        final String klazz = goodClassName(x.getClass());
501 +        return Stream.of(
502 +            new Job(klazz + " removeIf") {
503 +                public void work() throws Throwable {
504 +                    int[] sum = new int[1];
505 +                    for (int i = 0; i < iterations; i++) {
506 +                        sum[0] = 0;
507 +                        if (x.removeIf(n -> { sum[0] += n; return false; }))
508 +                            throw new AssertionError();
509 +                        check.sum(sum[0]);}}},
510 +            new Job(klazz + " remove(Object)") {
511 +                public void work() throws Throwable {
512 +                    int[] sum = new int[1];
513 +                    Object sneakyAdder = sneakyAdder(sum);
514 +                    for (int i = 0; i < iterations; i++) {
515 +                        sum[0] = 0;
516 +                        if (x.remove(sneakyAdder)) throw new AssertionError();
517 +                        check.sum(sum[0]);}}});
518 +    }
519 +
520      Stream<Job> dequeJobs(Deque<Integer> x) {
521          String klazz = goodClassName(x.getClass());
522          return Stream.of(
# Line 555 | Line 574 | public class IteratorMicroBenchmark {
574                          if (x.lastIndexOf(sneakyAdder) != -1)
575                              throw new AssertionError();
576                          check.sum(sum[0]);}}},
558            new Job(klazz + " replaceAll") {
559                public void work() throws Throwable {
560                    int[] sum = new int[1];
561                    UnaryOperator<Integer> sneakyAdder =
562                        x -> { sum[0] += x; return x; };
563                    for (int i = 0; i < iterations; i++) {
564                        sum[0] = 0;
565                        x.replaceAll(sneakyAdder);
566                        check.sum(sum[0]);}}},
577              new Job(klazz + " equals") {
578                  public void work() throws Throwable {
579                      ArrayList<Integer> copy = new ArrayList<>(x);
# Line 577 | Line 587 | public class IteratorMicroBenchmark {
587                          if (x.hashCode() != hashCode)
588                              throw new AssertionError();}}});
589      }
590 +
591 +    Stream<Job> mutableListJobs(List<Integer> x) {
592 +        final String klazz = goodClassName(x.getClass());
593 +        return Stream.of(
594 +            new Job(klazz + " replaceAll") {
595 +                public void work() throws Throwable {
596 +                    int[] sum = new int[1];
597 +                    UnaryOperator<Integer> sneakyAdder =
598 +                        x -> { sum[0] += x; return x; };
599 +                    for (int i = 0; i < iterations; i++) {
600 +                        sum[0] = 0;
601 +                        x.replaceAll(sneakyAdder);
602 +                        check.sum(sum[0]);}}});
603 +    }
604   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines