def benchmark(int count, Closure worker) { def start = System.nanoTime() count.times { worker(it) } def stop = System.nanoTime() return stop - start } def intCast = benchmark(500000) { (int) it / 2 } def intMeth = benchmark(500000) { it.intdiv(2) } println "Integer cast: ${intCast/intCast * 100}%" println "Method call: ${(intMeth/intCast * 100).toFloat().round(1)}%"