56 |
|
import java.util.concurrent.CountDownLatch; |
57 |
|
import java.util.concurrent.ThreadLocalRandom; |
58 |
|
import java.util.concurrent.TimeUnit; |
59 |
+ |
import java.util.concurrent.atomic.LongAdder; |
60 |
|
import java.util.regex.Pattern; |
61 |
|
|
62 |
|
/** |
392 |
|
for (Integer o : x.toArray(empty)) |
393 |
|
sum[0] += o; |
394 |
|
check.sum(sum[0]);}}}, |
395 |
+ |
new Job(klazz + " stream().forEach") { |
396 |
+ |
public void work() throws Throwable { |
397 |
+ |
int[] sum = new int[1]; |
398 |
+ |
for (int i = 0; i < iterations; i++) { |
399 |
+ |
sum[0] = 0; |
400 |
+ |
x.stream().forEach(n -> sum[0] += n); |
401 |
+ |
check.sum(sum[0]);}}}, |
402 |
+ |
new Job(klazz + " stream().mapToInt") { |
403 |
+ |
public void work() throws Throwable { |
404 |
+ |
for (int i = 0; i < iterations; i++) { |
405 |
+ |
check.sum(x.stream().mapToInt(e -> e).sum());}}}, |
406 |
|
new Job(klazz + " stream().collect") { |
407 |
|
public void work() throws Throwable { |
408 |
|
for (int i = 0; i < iterations; i++) { |
409 |
|
check.sum(x.stream() |
410 |
|
.collect(summingInt(e -> e)));}}}, |
411 |
+ |
new Job(klazz + " parallelStream().forEach") { |
412 |
+ |
public void work() throws Throwable { |
413 |
+ |
for (int i = 0; i < iterations; i++) { |
414 |
+ |
LongAdder sum = new LongAdder(); |
415 |
+ |
x.parallelStream().forEach(n -> sum.add(n)); |
416 |
+ |
check.sum((int) sum.sum());}}}, |
417 |
+ |
new Job(klazz + " parallelStream().mapToInt") { |
418 |
+ |
public void work() throws Throwable { |
419 |
+ |
for (int i = 0; i < iterations; i++) { |
420 |
+ |
check.sum(x.parallelStream().mapToInt(e -> e).sum());}}}, |
421 |
|
new Job(klazz + " parallelStream().collect") { |
422 |
|
public void work() throws Throwable { |
423 |
|
for (int i = 0; i < iterations; i++) { |