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.

11 lines
380 B

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