咖啡伴侶

          呆在上海
          posts - 163, comments - 156, trackbacks - 0, articles - 2

          sax,script包在android中的效率

          Posted on 2011-08-03 14:18 oathleo 閱讀(1506) 評論(0)  編輯  收藏
          和奇怪,調試模式下的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;
              }

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 通江县| 麟游县| 浦城县| 龙井市| 琼海市| 屏东市| 佛山市| 海晏县| 清水县| 奉化市| 凉山| 玉溪市| 壶关县| 黎城县| 武平县| 东宁县| 都兰县| 东乡县| 玉田县| 内江市| 红安县| 永仁县| 海原县| 新平| 共和县| 修武县| 沐川县| 桃园市| 富源县| 枣阳市| 阿尔山市| 杨浦区| 无为县| 涟源市| 临海市| 张家口市| 阿荣旗| 黔江区| 密云县| 保靖县| 武鸣县|