Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1.  
  2. def time[R](name: String)(block: => R): R = {
  3. val t0 = System.currentTimeMillis()
  4. val result = block
  5. val t1 = System.currentTimeMillis()
  6. println(s" $name time: " + (t1 - t0) + "ns")
  7. result
  8. }
  9.  
  10. val Times = 1000000
  11.  
  12. case object dummy{
  13. val data = List.fill(10000)("aaa")
  14. }
  15.  
  16. case object data {
  17. val dlist = List.fill(Times)(dummy)
  18. }
  19.  
  20. val reverseTime = time("reverseTime") { 1 to 1000 foreach { _ =>
  21. data.dlist.reverse.head
  22. }
  23. }
  24. val lastTime = time("lastTime") { 1 to 1000 foreach { _ =>
  25. data.dlist.last
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement