home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (BenchmarkBug.groovy)

This example Groovy source code file (BenchmarkBug.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

benchmarkbug, benchmarkbug, groovytestcase, groovytestcase, performed, performed

The Groovy BenchmarkBug.groovy source code

package groovy.bugs

/**
 * A little performance test
 * @version $Revision: 4996 $
 */
class BenchmarkBug extends GroovyTestCase {
    
    void testPerformance() {
        def start = System.currentTimeMillis()

        def total = 0
        def size = 10000
        for (i in 0..size) {
            total = total + callSomeMethod("hello", total)
        }

        def end = System.currentTimeMillis()

        def time = end - start

        println "Performed ${size} iterations in ${time / 1000} seconds which is ${time / size} ms per iteration"

        // TODO: parser bug
        // assert total == size * 10 + 10
        assert total == 100010
    }
    
    def callSomeMethod(text, total) {
        return 10
    }
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy BenchmarkBug.groovy source code file:

new blog posts

 

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.