Created
September 25, 2015 08:55
-
-
Save amaembo/d86d51c332a724da488e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JDK flatMap | |
Thread[ForkJoinPool.commonPool-worker-7,5,main]=156250 | |
Thread[ForkJoinPool.commonPool-worker-4,5,main]=31250 | |
Thread[ForkJoinPool.commonPool-worker-1,5,main]=125000 | |
Thread[ForkJoinPool.commonPool-worker-6,5,main]=218750 | |
Thread[main,5,main]=62500 | |
Thread[ForkJoinPool.commonPool-worker-3,5,main]=125000 | |
Thread[ForkJoinPool.commonPool-worker-2,5,main]=125000 | |
Thread[ForkJoinPool.commonPool-worker-5,5,main]=156250 | |
Holger's flatMap | |
Thread[ForkJoinPool.commonPool-worker-7,5,main]=136980 | |
Thread[ForkJoinPool.commonPool-worker-4,5,main]=130624 | |
Thread[ForkJoinPool.commonPool-worker-1,5,main]=133932 | |
Thread[ForkJoinPool.commonPool-worker-6,5,main]=169549 | |
Thread[main,5,main]=1 | |
Thread[ForkJoinPool.commonPool-worker-3,5,main]=147063 | |
Thread[ForkJoinPool.commonPool-worker-2,5,main]=142912 | |
Thread[ForkJoinPool.commonPool-worker-5,5,main]=138939 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
System.out.println("JDK flatMap"); | |
Map<Thread, Integer> threads = new ConcurrentHashMap<>(); | |
IntStream.range(0, 1000000).boxed().flatMap(Stream::of).parallel() | |
.peek(e -> threads.merge(Thread.currentThread(), 1, Integer::sum)) | |
.collect(Collectors.summingInt(Integer::intValue)); | |
threads.entrySet().forEach(System.out::println); | |
} | |
{ | |
System.out.println("Holger's flatMap"); | |
Map<Thread, Integer> threads = new ConcurrentHashMap<>(); | |
flatMap(IntStream.range(0, 1000000).boxed(), Stream::of).parallel() | |
.peek(e -> threads.merge(Thread.currentThread(), 1, Integer::sum)) | |
.collect(Collectors.summingInt(Integer::intValue)); | |
threads.entrySet().forEach(System.out::println); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment