Skip to content

Instantly share code, notes, and snippets.

@d6y
Created July 22, 2012 15:52
Show Gist options
  • Select an option

  • Save d6y/3160066 to your computer and use it in GitHub Desktop.

Select an option

Save d6y/3160066 to your computer and use it in GitHub Desktop.
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