Groovy vs BeanShell
Quick speed performance test
Below is a quick and dirty test to compare the speed performance between bean shell and groovy. Bean shell is an order of magnitude faster. If you don't need groovy closure and other nice groovy features...just use bean shell. It's only one small jar away.
slashdot
public static void main(String[] args) throws EvalError {
StringBuilder script = new StringBuilder();
for (int i=0;i<900;i++) {
script.append("res");
script.append(i);
script.append("=");
script.append(i+"+"+i+"*"+i);
script.append(";\n");
}
GroovyShell groovyShell = new GroovyShell();
Interpreter bsh = new Interpreter();
long t = System.currentTimeMillis();
groovyShell.evaluate(script.toString());
System.out.println(System.currentTimeMillis() - t);
t = System.currentTimeMillis();
for (int i=0;i<1000;i++) {
int j = i+i*i;
}
System.out.println(System.currentTimeMillis() - t);
t = System.currentTimeMillis();
bsh.eval(script.toString());
System.out.println(System.currentTimeMillis() - t);
}




Re: Groovy vs BeanShell
you get the opposite effect if you parse the groovy script once... i don't know if beanshell has an equivalent... but I don't see one.
public static void main(String[] args) throws EvalError { StringBuilder script = new StringBuilder(); for (int i = 0; i < 900; i++) { script.append("res"); script.append(i); script.append("="); script.append(i + "+" + i + "*" + i); script.append(";\n"); } GroovyShell groovyShell = new GroovyShell(); Script groovyScript = groovyShell.parse(script.toString()); Interpreter bsh = new Interpreter(); long t; for(int i=0; i < 10; i++) { t = System.currentTimeMillis(); groovyScript.run(); System.out.println("groovy run "+i+": " + (System.currentTimeMillis() - t)); t = System.currentTimeMillis(); bsh.eval(script.toString()); System.out.println("bsh run "+i+" : " + (System.currentTimeMillis() - t)); System.out.println(""); } }