Last active
June 16, 2016 06:01
-
-
Save fran0x/429a8eaf7edb81a42e2663e6c23214c2 to your computer and use it in GitHub Desktop.
Utility code for time measurement
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
// Measure.time is used to measure the time that takes to complete a block of code (in nanoseconds) | |
// note: this version does not return the result of calling that function; a different version should be created for that | |
object Measure { | |
def time(block: => Unit)={ | |
val s = System.nanoTime | |
block | |
System.nanoTime - s | |
} | |
} | |
// example of usage | |
object Test extends App { | |
def count(i: Int) = for (j <- 1 to i) {} | |
import Measure._ | |
println("Elapsed time: " + time(count(10000000))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment