Skip to content

Instantly share code, notes, and snippets.

@dnene
Created July 24, 2018 13:48
Show Gist options
  • Save dnene/43cc9ad95768190ee3902bde1406b2c9 to your computer and use it in GitHub Desktop.
Save dnene/43cc9ad95768190ee3902bde1406b2c9 to your computer and use it in GitHub Desktop.
Time Sequence vs No Sequencce
import kotlin.system.measureTimeMillis
fun main(args: Array<String>) {
val iterations = 10000000
val time1 = measureTimeMillis {
(1..iterations).forEach {
val result: List<Int> = (1..100).filter { it % 2 == 0 }.filter { it % 3 == 0 }.filter { it % 5 == 0 }
}
}
val time2 = measureTimeMillis {
(1..iterations).forEach {
val result: List<Int> = (1..100).asSequence().filter { it % 2 == 0 }.filter { it % 3 == 0 }.filter { it % 5 == 0 }.toList()
}
}
println("${time1} ${time2}") // 8754 15496
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment