我需要在 Scala 中计算代码的运行时间。代码是。
val data = sc.textFile("/home/david/Desktop/Datos Entrada/household/household90Parseado.txt")
val parsedData = data.map(s => Vectors.dense(s.split(' ').map(_.toDouble))).cache()
val numClusters = 5
val numIterations = 10
val clusters = KMeans.train(parsedData, numClusters, numIterations)
我需要知道处理此代码的运行时,时间必须以秒为单位。
最佳答案
基于讨论 here ,你会想要使用 System.nanoTime
测量耗时差:
val t1 = System.nanoTime
/* your code */
val duration = (System.nanoTime - t1) / 1e9d
关于scala - 我如何知道 Scala 中代码的运行时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37730808/