gpt4 book ai didi

scala - 我如何知道 Scala 中代码的运行时间?

转载 作者:行者123 更新时间:2023-12-04 00:01:17 30 4
gpt4 key购买 nike

我需要在 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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com