Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I know the runtime of a code in scala?

Tags:

I need to calculate the runtime of a code in scala. The code is.

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) 

I need to know the runtime to process this code, the time have to be on seconds.

like image 556
David Rebe Garcia Avatar asked Jun 09 '16 15:06

David Rebe Garcia


People also ask

What is Scala runtime?

Yes, Scala runtime runs on top of JVM and all it needs is supporting scala-lang. jar library and "a plain" JVM of appropriate version. Scala code is compiled to JVM bytecode.


1 Answers

Based on discussion here, you'll want to use System.nanoTime to measure the elapsed time difference:

val t1 = System.nanoTime  /* your code */  val duration = (System.nanoTime - t1) / 1e9d 
like image 100
evan.oman Avatar answered Sep 28 '22 03:09

evan.oman