Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tim's long adder test with streams but groovier :-)
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
@glaforge

This comment has been minimized.

Copy link
Owner Author

@glaforge glaforge commented Apr 30, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment