Skip to content

Gorgeous GBench

I’ve been known to indulge my OCD and post a very few trivial micro-benchmarks.

Each time I just hacked a simple Groovy script together I thought “there must be a better way.”

Turns out, there is: GBench: “a benchmarking module for Groovy.”

To see how GBench works, I took an earlier benchmark and re-worked it for GBench, viz:

@Grab('com.googlecode.gbench:gbench:0.4.1-groovy-2.1') // v0.4.1 for Groovy 2.1

def r = benchmark(verbose: true) {
    'Each' {
        def i = 0
        (1..100000000).each { i ++ }
    'For' {
        def i = 0
        for (x in 1..100000000) { i ++ }

And the result:

* Groovy: 2.1.2
* JVM: Java HotSpot(TM) 64-Bit Server VM (23.7-b01, Oracle Corporation)
    * JRE: 1.7.0_17
    * Total Memory: 127.875 MB
    * Maximum Memory: 127.875 MB
* OS: Windows 8 (6.2, amd64) 

* Warm Up: Auto (- 60 sec)
* CPU Time Measurement: On

Warming up "Each"...
Measuring "Each"...
Warming up "For"...
Measuring "For"...
            user  system         cpu        real

Each  7859375000       0  7859375000  8111961507
For   2250000000       0  2250000000  2304534377

Simple, easy. What’s not to like!

Tags: ,

C, Java Enterprise Edition, JEE, J2EE, JBoss, Application Server, Glassfish, JavaServer Pages, JSP, Tag Libraries, Servlets, Enterprise Java Beans, EJB, Java Messaging Service JMS, BEA Weblogic, JBoss, Application Servers, Spring Framework, Groovy, Grails, Griffon, GPars, GAnt, Spock, Gradle, Seam, Open Source, Service Oriented Architectures, SOA, Java 2 Standard Edition, J2SE, Eclipse, Intellij, Oracle Service Bus, OSB