Groovy-Java性能对比

先说结论,如摘要所述,用Groovy的语法糖的同时若是苛求性能,就加@CompileStatic编译注解。git

下面是用punit作的2次并发性能测试结果,第一次是执行一个简单的方法调用,第二个是模拟一个耗时的业务方法。并发

工程代码,请参考个人git:性能

http://git.oschina.net/key232323/groovy-performance-test测试


第一次:(只作计算)
spa

[concurrent] Starting com.innohub.bench.runner.Tester.net

com.innohub.bench.runner.Testerorm

testDoCalJava() - [0.007931ms]ip

testGroovyInterfaceAndStatic() - [0.006531ms]it

testGroovyInterface() - [0.078376ms]编译

testGroovyScript() - [0.099371ms]

total: 4, failures:0 (GREEN) - 919.502066ms

[concurrent] Starting com.innohub.bench.runner.Tester

com.innohub.bench.runner.Tester

testDoCalJava() - [0.006065ms]

testGroovyInterfaceAndStatic() - [0.007464ms]

testGroovyInterface() - [0.078376ms]

testGroovyScript() - [0.106368ms]

total: 4, failures:0 (GREEN) - 85.572821ms

[concurrent] Starting com.innohub.bench.runner.Tester

com.innohub.bench.runner.Tester

testDoCalJava() - [0.007931ms]

testGroovyInterfaceAndStatic() - [0.005598ms]

testGroovyInterface() - [0.079777ms]

testGroovyScript() - [0.091906ms]

total: 4, failures:0 (GREEN) - 500.078843ms


第二次:(Sleep 10ms模拟耗时的业务方法

[concurrent] Starting com.innohub.bench.runner.Tester

com.innohub.bench.runner.Tester

testDoCalJava() - [10053.493918ms]

testGroovyInterfaceAndStatic() - [10041.729026ms]

testGroovyInterface() - [10185.924769ms]

testGroovyScript() - [10039.974882ms]

total: 4, failures:0 (GREEN) - 41040.644815ms

[concurrent] Starting com.innohub.bench.runner.Tester

com.innohub.bench.runner.Tester

testDoCalJava() - [10058.807668ms]

testGroovyInterfaceAndStatic() - [10050.167577ms]

testGroovyInterface() - [10063.309659ms]

testGroovyScript() - [10067.116524ms]

total: 4, failures:0 (GREEN) - 40332.292666ms

[concurrent] Starting com.innohub.bench.runner.Tester

com.innohub.bench.runner.Tester

testDoCalJava() - [10028.900451ms]

testGroovyInterfaceAndStatic() - [10028.953634ms]

testGroovyInterface() - [10042.517924ms]

testGroovyScript() - [10037.078679ms]

total: 4, failures:0 (GREEN) - 40468.62882ms