With the reflection-based closure approach from last post, I've got some codes to compare performance.
The following is a Groovy code,
class TestGen_002 {
def a = {
1000000.times {
println it
}
}
}
And this is the manually translated code. Class TestGen_002 contains reflection-based closures, a and an anonymous closure for times.
package org.codehaus.qdg;
import org.codehaus.groovy.qdg.Closure;
import org.codehaus.qdg.runtime.DefaultMethods;
public class TestGen_002 {
public Closure a = new Closure(this, "a__0");
private Object a__0(Object... args) {
Closure a$a = new Closure(this, "a$a__0");
DefaultMethods.times(1000000, a$a);
return null;
}
private Object a$a__0(Object... args) {
System.out.println(args[0]);
return null;
}
}
Although it's fast, 28 secs, compared with traditional Java for loop (22 secs). I've been trying to get its speed closer to Java.
No comments:
Post a Comment