Created
July 22, 2012 15:52
-
-
Save d6y/3160066 to your computer and use it in GitHub Desktop.
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(opname, block) | |
| { | |
| long start\_time = System.nanoTime() | |
| boolean success = true | |
| try { | |
| return block() | |
| } catch (Throwable ex) { | |
| success = false; | |
| throw ex | |
| } finally { | |
| diff = System.nanoTime() - start_time | |
| println "$opname $diff $success" | |
| } | |
| } | |
| int f() throws Exception { | |
| time("a") { | |
| Random r = new Random() | |
| if (r.nextInt(100) > 50) | |
| throw new IOException("Boom") | |
| else | |
| return 42 | |
| } | |
| time("b") { | |
| return 7 | |
| } | |
| } | |
| println f() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment