Create a gist now

Instantly share code, notes, and snippets.

def bench(code: => Any, times: Int = 1) {
val start = System.nanoTime
for(_ <- 1 to times) code
println(format("%.4f", (System.nanoTime - start)/1000000000.0))
}
scala> bench( 1+1 )
0.0000
scala> bench( 1+1, 10000)
0.0020
scala> bench( List("a"->"b"), 1000000 )
0.2600
scala> bench( Set("a"->"b"), 1000000 )
0.2170
scala> bench( Map("a"->"b"), 1000000 )
0.1610
scala> bench( ("a"->"b"), 1000000 )
0.0530
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment