Created
December 2, 2009 19:52
-
-
Save p3t0r/247489 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
object Time { | |
def apply[T](name: String)(block: => T) { | |
val start = System.currentTimeMillis | |
try { | |
block | |
} finally { | |
val diff = System.currentTimeMillis - start | |
println("# Block \"" + name +"\" completed, time taken: " + diff + " ms (" + diff / 1000.0 + " s)") | |
} | |
} | |
} | |
val list = (0 to 10000).toList | |
val two = 2 | |
Time("and multiply by 2 in val") { | |
list.foreach( _ * two ) | |
} | |
Time("and multiply by 2") { | |
list.foreach( _ * 2 ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment