... milliseconds: %d%n%n",
46            Duration.between(sequentialStart, sequentialEnd).toMillis());
47
48         // time sum operation with parallel stream
49         LongStream stream2 = Arrays.stream(values).parallel();
50         System.out.println("Calculating statistics on parallel stream");
51         Instant parallelStart = Instant.now();
52         LongSummaryStatistics results2 = stream2.summaryStatistics();
53         Instant parallelEnd = Instant.now();
54
55         // display results
56         displayStatistics(results1);
57         System.out.printf("Total time in milliseconds: %d%n%n",
58            Duration.between(parallelStart, parallelEnd).toMillis());
59      }
60
61      // display's LongSummaryStatistics values
62      private static void displayStatistics(LongSummaryStatistics stats) {
63         System.out.println("Statistics");
64 System.out.printf( ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.