Slow forEach in Kotlin for ranges
I used the following code to measure performance of different syntax constructions in Kotlin
fun time(what: String, body: () -> Int) {
val start = System.currentTimeMillis()
var sum = 0
repeat(10) {
sum += body()
}
val end = System.currentTimeMillis()
println("$what: ${(end - start) / 10}")
}
val n = 200000000
val rand = Random()
val arr = IntArray(n) { rand.nextInt() }
time("for in range") {
var sum = 0
for (i in (0 until n))
sum +=...