Skip to content

Instantly share code, notes, and snippets.

@maowug
Created August 24, 2016 09:05
Show Gist options
  • Save maowug/26815351e2ea447e3e52fcd4b5195374 to your computer and use it in GitHub Desktop.
Save maowug/26815351e2ea447e3e52fcd4b5195374 to your computer and use it in GitHub Desktop.
simple block timer
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