precision

This commit is contained in:
kamoshi 2019-12-09 11:03:21 +01:00 committed by GitHub
parent 83c8b6149b
commit a3f03ffcda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,15 +4,15 @@ package kamlib
class Wrapper[A](function: => A)
{
/** Saved results */
val tuple: (A, Int) = wrap(function)
val tuple: (A, Double) = wrap(function)
/** Time measurement */
private[this] def wrap[A](function: => A): (A, Int) =
private[this] def wrap[A](function: => A): (A, Double) =
{
val evalStart = System.currentTimeMillis()
val evalStart = System.nanoTime()
val result = function
val evalEnd = System.currentTimeMillis()
(result, (evalEnd-evalStart).toInt)
val evalEnd = System.nanoTime()
(result, ((evalEnd-evalStart)/100).toDouble/10000)
}
def print(): Unit =
@ -20,7 +20,7 @@ class Wrapper[A](function: => A)
println(s"Result: ${tuple._1} | Time: ${tuple._2}ms")
}
def result: A = tuple._1
def time: Int = tuple._2
def time: Double = tuple._2
}
object Wrapper