I am going through Groovy Closures, and I came to a particular section in Groovy in Action which talks about using Closures. I tweaked the code a little as below:-
def benchmark(int repeat, Closure worker){
def start = System.nanoTime()
repeat.times {worker(it)}
def stop = System.nanoTime()
return stop-start
}
def slow = benchmark(10){println('1')}
def fast = benchmark(10){println('1')}
println(slow)
println(fast)
Now the variable slow is always greater than fast. How is that possible? When we are calling the benchmark method with the same parameters each time?
PS:- Very new to SO community, do correct me if I made some mistake in asking question as above. Thanks