Timing a closure in Groovy
When you want to make some optimizations to your code, you often use the good old System.currentTimeMillis() method to time certain parts of your application. I wanted to do a similar thing when hacking some Groovy scripts recently, and the idea came to me that I could simply create a timing closure! So here it is, for your eyes only:
timer = { closure ->
start = System.currentTimeMillis()
closure()
println System.currentTimeMillis() - start
}
Then you can use your brand new timing closure:
Read more...