My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Wiki pages
Links

What is GBench?

GBench is a benchmarking framework for Groovy.

Is GBench available on Maven Central?

Yes. So GBench can be installed also via Grape:

@Grab(group='com.googlecode.gbench', module='gbench', version='0.2.2')
import gbench.*

You can check available versions here.

What features does GBench provide?

  • Benchmark AST Transformation: An AST Transformation alllows you to benchmark methods without modifying their existing code. See the annotation javadoc for details.
    • Example:
      • Source code:
      • import gbench.*
        
        class MyApp {
            @Benchmark
            def aMethod() {
            }
        }
      • Output:
      • MyApp  java.lang.Object aMethod()  user:15600100 system:46800300 cpu:62400400 real:396709428
  • Benchmark Builder: A Builder allows you to write micro-benchmark code quickly easily, and simply. See the class javadoc for details.
    • Example:
      • Source code:
      • import gbench.*
        
        def benchmarker = new BenchmarkBuilder()
        def benchmarks = benchmarker.average(repeat: 5, idle: 1) {
            int num = 25
            'recursive fibonacci' {
                { n ->
                    if (n < 2) return n
                    return call(n - 1) + call(n - 2)
                }(num)
            }
            'iterative fibonacci' {
               { n ->
                    int a = 0
                    int b = 1
                    int c
                    for (int i in 2..n) {
                        c = a + b
                        a = b
                        b = c
                    }
                    return b
                }(num)
            }
        }
        benchmarks.sort().prettyPrint()
      • Output:
      •                               user        system               cpu            real
        
        iterative fibonacci              0             0                 0          647596
        recursive fibonacci     2923458740      18720120        2942178860      2947965327
Powered by Google Project Hosting