MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / main

Method main

concurrent/Summing2.java:21–36  ·  view source on GitHub ↗
(String[] args)

Source from the content-addressed store, hash-verified

19 public static final long CHECK =
20 (long)SZ * ((long)SZ + 1)/2;
21 public static void main(String[] args) {
22 System.out.println(CHECK);
23 long[] la = new long[SZ+1];
24 Arrays.parallelSetAll(la, i -> i);
25 Summing.timeTest("Array Stream Sum", CHECK, () ->
26 Arrays.stream(la).sum());
27 Summing.timeTest("Parallel", CHECK, () ->
28 Arrays.stream(la).parallel().sum());
29 Summing.timeTest("Basic Sum", CHECK, () ->
30 basicSum(la));
31 // Destructive summation:
32 Summing.timeTest("parallelPrefix", CHECK, () -> {
33 Arrays.parallelPrefix(la, Long::sum);
34 return la[la.length - 1];
35 });
36 }
37}
38/* Output:
39200000010000000

Callers

nothing calls this directly

Calls 5

timeTestMethod · 0.95
basicSumMethod · 0.95
sumMethod · 0.80
parallelSetAllMethod · 0.45
streamMethod · 0.45

Tested by

no test coverage detected