Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
O(n) size by default... great.
def time[R](block: => R): R = {
val t0 = System.currentTimeMillis
val result = block // call-by-name
val t1 = System.currentTimeMillis
println("Elapsed time: " + (t1 - t0) + "ms")
result
}
val list1 = 1 to 10000 toList
val ary1 = 1 to 10000 toArray
time { (1 to 1000000).foreach { _ => list1.size } } // Elapsed time: 22672ms
time { (1 to 1000000).foreach { _ => ary1.size } } // Elapsed time: 20ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.