Created
July 24, 2018 13:48
-
-
Save dnene/43cc9ad95768190ee3902bde1406b2c9 to your computer and use it in GitHub Desktop.
Time Sequence vs No Sequencce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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