Created
January 22, 2015 21:40
-
-
Save azakordonets/6eef4e7a8cecbbfa857b to your computer and use it in GitHub Desktop.
This small code allows you to test how much time does it take to execute your code
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
| def time[R](block: => R): R = { | |
| val t0 = System.nanoTime() | |
| val result = block // call-by-name | |
| val t1 = System.nanoTime() | |
| println("Elapsed time: " + (t1 - t0) + "ns") | |
| result | |
| } | |
| // Now wrap your method calls, for example change this... | |
| val result = 1 to 1000 sum | |
| // ... into this | |
| val result = time { 1 to 1000 sum } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment