Posted on 2011-08-03 14:18
oathleo 閱讀(1505)
評(píng)論(0) 編輯 收藏
和奇怪,調(diào)試模式下的SAX和script
效率巨慢,而運(yùn)行模式下,好很多,大概快5-10倍。
另外script包會(huì)編譯一個(gè)print方法,這個(gè)過(guò)程耗時(shí)很多,嚴(yán)重影響效率
去掉并做些優(yōu)化后
500條腳本,執(zhí)行從1s縮減到200ms
代碼精簡(jiǎn)如下:
RhinoScriptEngine.java
Scriptable getRuntimeScope(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
//去掉下面幾行
// Context cx = enterContext();
// try {
// cx.evaluateString(newScope, printSource, "print", 1, null);
// } finally {
// cx.exit();
// }
return newScope;
}