Mandar
未读,2012年4月1日 00:08:532012/4/1登录即可回复作者
登录即可转发
您无权在此群组中删除帖子
请登录以举报消息
要么此群组的电子邮件地址为匿名状态,要么您得查看成员电子邮件地址权限才能查看原始帖子
收件人 Groovy++
For a fairly simple piece of code, Groovy++ seems to be about 1000
times slower than Groovy. Any idea why?
If I simply remove the @Typed annotation, both methods run at the same
speed. If I change to integer types instead of the BigInteger (i.e.,
drop the G suffixes), the Groovy++ code is faster.
regards,
Mandar
---
CODE:
// warm up
for (i in 0..100) {
fib(1000)
fibPP(1000)
}
// test Groovy++ and Groovy timings
t = System.currentTimeMillis()
println fib(10000)
println System.currentTimeMillis()-t
t = System.currentTimeMillis()
println fibPP(10000)
println System.currentTimeMillis()-t
// Groovy++ version
@Typed
static def fibPP(int n) {
def a = 0G
def b = 1G
def x = 1G
for (i in 0..<n) {
def y = x
x = a + b
a = b
b = y
}
x
}
// Groovy version
static def fib(n) {
def a = 0G
def b = 1G
def x = 1G
for (i in 0..<n) {
(x,a,b) = [a+b,b,x]
}
x
}