当前位置:操作系统 > 安卓/Android >>

sax,script包在android中的效率

 

调试模式下的SAX和script

效率巨慢,而运行模式下,好很多,大概快5-10倍。

 

另外script包会编译一个print方法,这个过程耗时很多,严重影响效率

去掉并做些优化后

500条脚本,执行从1s缩减到200ms

 

代码精简如下:

 

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;

    }

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,