benchmarkbug.groovy

来自「Groovy动态语言 运行在JVM中的动态语言 可以方便的处理业务逻辑变化大的业」· GROOVY 代码 · 共 30 行

GROOVY
30
字号
/**
 * A little performance test
 * @version $Revision: 2284 $
 */
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
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?