Why is Groovy++ 1000x slower than Groovy in some cases?

128 views
Skip to first unread message

Mandar

unread,
Apr 1, 2012, 12:08:53 AM4/1/12
to 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
}
Reply all
Reply to author
Forward
0 new messages