Last active
October 4, 2016 01:28
-
-
Save djk29a/4a393b2633885ab01bee to your computer and use it in GitHub Desktop.
Simple Scala timer I haven't tried to use since Scala 2.08
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
| object Timer { | |
| def time[R](block: => R): Pair[Long,_] = { | |
| val t0 = System.nanoTime() | |
| val result = block | |
| val diff = System.nanoTime() - t0 | |
| // Post-timing processing can be added here, maybe | |
| // an optional argument to this method? | |
| Pair(diff, result) | |
| } | |
| } |
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
| defined module Timer | |
| scala> val result = Timer.time { Thread.sleep(1234); 34 } | |
| result: (Long, Any) = (1235042000,34) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Timer object can accept a block and return the block. No need for annotations ala AOP style code