Skip to content

Instantly share code, notes, and snippets.

@satoshun
Last active July 2, 2017 12:39
Show Gist options
  • Save satoshun/f9a81ea3f6deab0322de70e67c86c43f to your computer and use it in GitHub Desktop.
Save satoshun/f9a81ea3f6deab0322de70e67c86c43f to your computer and use it in GitHub Desktop.
@Test fun list() {
  println(measureTimeMillis {
    println((0..10000000)
        .filter { it % 2 == 0}
        .map { it * it }
        .map { it - 10 }.size)
  })
}

// こっちのほうが早い
@Test fun sequence() {
  println(measureTimeMillis {
    println((0..10000000).asSequence()
        .filter { it % 2 == 0 }
        .map { it * it }
        .map { it - 10 }
        .toList().size)
  })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment