#4 Performance: 1.2b6, 1.3.0, 2.0b4

open
nobody
None
5
2005-10-05
2005-10-05
Anonymous
No

stevehale@bigfoot.com

BeanShell is used to evaluate user-defined numeric and
boolean expressions within a web application. For
example, an expression like: b = ((v0 + v1) > 0 && (v2 >
0); These expressions are defined ahead of time, but
used over and over by multiple concurrent threads.

I have found significant performance degredation in later
versions of BeanShell, probably due to increased
functionality in other areas (like Java 1.5 support).
However any suggestions would be appreciated.

The code fragment below illustrates the relative
performance of the three libraries tested. A new
interpreter is created in each loop similar to creating a
new one for each thread. It is unclear whether variables
can be set on a statically held interpreter and still be
threadsafe, so I have assumed not. Because of this,
putting the expression in a method would not help.

At 10,000 iterations of the outer loop:
1.2b6 = 13 seconds
1.3.0 = 54 seconds
2.0b4 = 133 seconds

//Test BeanShell expressions
System.out.println("BeanShell Test...");
elapsed = System.currentTimeMillis();
n=THOUSAND10;
for (i = n; i > 0; i--) {
bsh.Interpreter javaInterpreter = new
bsh.Interpreter();
try {
for (int nVar=0; nVar < 10; nVar++)
javaInterpreter.set("v"+nVar, (double)nVar);
Double dEval = (Double)javaInterpreter.eval
("(v0 + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9) / 2");
if (cat.isDebugEnabled()) cat.debug("dEval
= " +dEval);
} catch ( bsh.EvalError ex ) {
cat.error("Java Interpreter error: "
+ex.getErrorText());
}
}
elapsed = System.currentTimeMillis() - elapsed;
System.out.println("" +n+ "* bshTest = "
+millisToString(elapsed));

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks