Created
September 8, 2011 15:27
-
-
Save bdarfler/1203677 to your computer and use it in GitHub Desktop.
Scala Microbenchmark Runner
This file contains 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
def benchmark(runs: Long, reps: Long, funct: => Any) = { | |
// warmup | |
println("Warming Up") | |
var i = 0 | |
while ( i < 25000 ) { funct; i = i + 1 } | |
// test runs | |
println("Running Test") | |
var j = 0 | |
while ( j < runs ) { | |
var k = 0 | |
val start = System.nanoTime() | |
while ( k < reps ) { funct; k = k + 1 } | |
val avgNanos = (System.nanoTime() - start) / reps | |
val avgMillis = avgNanos / 1000000f | |
println("Avg Execution Time: %s ms".format(avgMillis)) | |
j = j + 1 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment