Created
August 15, 2013 15:36
-
-
Save overthink/6241841 to your computer and use it in GitHub Desktop.
O(n) size by default... great.
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
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