Groovy-Java性能对比

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

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

工程代码,请参考我的git:

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


第一次:(只做计算)

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

com.innohub.bench.runner.Tester

testDoCalJava() - [0.007931ms]

testGroovyInterfaceAndStatic() - [0.006531ms]

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


转载于:https://my.oschina.net/u/2000379/blog/529250

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值