scala获取程序运行时间

来源:互联网 发布:创业方向 知乎 编辑:程序博客网 时间:2024/06/04 18:45
def timer[A](blockOfCode:=>A)={val starttime=System.nanoTime              //系统纳米时间val result=blockOfCodeval endtime=System.nanoTimeval delta=stoptime-starttime(result,delta/1000000d)}

scala> val (result,time)=timer{println("hello")}helloresult:Unit=()time:Double=0.512

其实就是call-by-name,so easy!
0 0
原创粉丝点击