Skip to content

Instantly share code, notes, and snippets.

@ryanlecompte
Created January 23, 2013 00:21
Show Gist options
  • Save ryanlecompte/4600352 to your computer and use it in GitHub Desktop.
Save ryanlecompte/4600352 to your computer and use it in GitHub Desktop.
Stream.continually vs. traditional while
scala> benchmark { var x = 0; Stream.continually({x += 1; x}).takeWhile(_ < 10000000).foreach(_ / 2) }
res7: Long = 823
scala> benchmark { var x = 0; while (x < 10000000) { x += 1; x / 2 } }
res8: Long = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment