-
-
Save glaforge/397fc259320ffd0f7c25 to your computer and use it in GitHub Desktop.
Tim's long adder test with streams but groovier :-)
This file contains 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
import java.util.Random | |
import java.util.concurrent.ConcurrentHashMap | |
import java.util.concurrent.atomic.LongAdder | |
import java.util.stream.IntStream | |
def frequencyMap = new ConcurrentHashMap<>() | |
def rnd = new Random() | |
IntStream.range( 0, 10000 ) | |
.parallel() | |
.forEach { n -> | |
def key = Double.valueOf( rnd.nextGaussian() + 5 ).intValue() | |
frequencyMap.computeIfAbsent( key, { k -> new LongAdder() } ).increment() | |
} | |
println frequencyMap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More options in @timyates original gist: https://gist.github.com/timyates/348066a6a749ad0676f7