Skip to content

Instantly share code, notes, and snippets.

@nihsmik
Created December 28, 2020 09:25
Show Gist options
  • Save nihsmik/8e8ac593b5a2607f116a8eccf0de9be9 to your computer and use it in GitHub Desktop.
Save nihsmik/8e8ac593b5a2607f116a8eccf0de9be9 to your computer and use it in GitHub Desktop.
Kotlin Performance Test: Iterable<T>.forEach
import kotlin.time.Duration
import kotlin.time.measureTime
fun main() {
val durations = mutableListOf<Duration>()
repeat(10) {
val duration = measureTime { (0..1_000_000).forEach { it + 1 } }
durations += duration
}
println(durations)
// [14.0ms, 7.96ms, 1.68ms, 1.70ms, 1.71ms, 1.86ms, 1.68ms, 1.68ms, 1.71ms, 1.74ms]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment