Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Java parallel stream is significantly faster than the same stream converted into a Kotlin sequence
import kotlin.streams.asSequence
import kotlin.system.measureTimeMillis
val k = 500000000L
println(measureTimeMillis {
java.util.stream.LongStream.range(1, k)
.parallel()
.asSequence()
.map { it.toString().length.toLong() }
.max() } )
println(measureTimeMillis {
java.util.stream.LongStream.range(1, k)
.parallel()
.map { it.toString().length.toLong() }
.max() } )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment