Misc. experiments in groovy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12 lines
380 B

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)}%"