Created
August 24, 2016 09:05
-
-
Save maowug/26815351e2ea447e3e52fcd4b5195374 to your computer and use it in GitHub Desktop.
simple block timer
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
def time[R](name: String)(block: => R): R = { | |
val t0 = System.currentTimeMillis() | |
val result = block | |
val t1 = System.currentTimeMillis() | |
println(s" $name time: " + (t1 - t0) + "ns") | |
result | |
} | |
val Times = 1000000 | |
case object dummy{ | |
val data = List.fill(10000)("aaa") | |
} | |
case object data { | |
val dlist = List.fill(Times)(dummy) | |
} | |
val reverseTime = time("reverseTime") { 1 to 1000 foreach { _ => | |
data.dlist.reverse.head | |
} | |
} | |
val lastTime = time("lastTime") { 1 to 1000 foreach { _ => | |
data.dlist.last | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment