Skip to content

Instantly share code, notes, and snippets.

@p3t0r
Created December 2, 2009 19:52
Show Gist options
  • Save p3t0r/247489 to your computer and use it in GitHub Desktop.
Save p3t0r/247489 to your computer and use it in GitHub Desktop.
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