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

相關文章
相關標籤/搜索