Created
November 11, 2015 22:15
-
-
Save jbn/eeebd9a2024168e564ee to your computer and use it in GitHub Desktop.
A script to test the time-expense of scala.math.ulp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.math.ulp | |
/** | |
* ThirdWay calls `ulp` occasionally. This script tries to assess costs. | |
*/ | |
def timeIt[R](f: => R): Long = { | |
val start = System.currentTimeMillis | |
f | |
System.currentTimeMillis - start | |
} | |
val n = 1000000 | |
val timings = (0 until n).map { i => | |
val x = i.toDouble | |
timeIt { ulp(x) } | |
} | |
val μ = timings.sum / n.toDouble | |
// # => On my MBP mid-2012 | |
println(s"Average timing: $μ ms") // # => 6.9E-5 ms | |
println(s"Ops per second: ${1.0/μ*1000}") // # => 1.4492753623188406E7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment