Scala<计算代码运行时间>

xiaoxiao2021-02-28  103

object Demo { def time[R](block: => R): R = { val start = System.nanoTime() val result = block // call-by-name val end = System.nanoTime() println("\n\n--------------------------------") println("past:[" + (end - start) + "ns]") println("--------------------------------") result } def main(args: Array[String]): Unit = { time {1 to 1000 by 1 toList} } }

转载请注明原文地址: https://www.6miu.com/read-58044.html

最新回复(0)