SAX and script in debug mode
The efficiency is extremely slow, and the running mode is much better, about 5-10 times faster.
In addition, the script package will compile a print method, which takes a lot of time and seriously affects the efficiency.
After removing and optimizing
500 scripts, which are reduced from 1 s to 200 ms
The code is simplified as follows:
RhinoScriptEngine. java
Scriptable getruntimesxt (ScriptContext ctxt ){
If (ctxt = null ){
Throw new NullPointerException ("null script context ");
}
// We create a scope for the given ScriptContext
Scriptable newScope = new ExternalScriptable (ctxt, indexedProps );
// Set the prototype of newScope to be 'toplevel' so that
// JavaScript standard objects are visible from the scope.
NewScope. setPrototype (topLevel );
// Define "context" variable in the new scope
NewScope. put ("context", newScope, ctxt );
// Define "print", "println" functions in the new scope
// Remove the following lines
// Context cx = enterContext ();
// Try {
// Cx. evaluateString (newScope, printSource, "print", 1, null );
//} Finally {
// Cx. exit ();
//}
Return newScope;
}