simple block timer

u.go
2016-08-24T09:05:16Z

simpleTimer.scala

|
| 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
| }
| }
|
|