RSS RSS feed | Atom Atom feed
Popular Articles: Tom Riddle's Magical Diary | AJAX Lego Robot | AJAX CAPTCHA | SQL Multisets

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.
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); }
slashdot digg del.icio.us technorati [more]



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("");
        }
    }

Re: Groovy vs BeanShell

Thanks for the input.

Add a comment Send a TrackBack