Mandar
unread,Apr 1, 2012, 12:08:53 AM4/1/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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
}