开发者

Javascript Rhino + JQuery simple script performance issue

Wanted to ask if it's possible today to have a good performance for running javascript in standalone mode with Rhino.

I have a performance issue running Rhino, EnvJS + JQuery script.

Here is the script:

load('tools/envjs/env.rhino.js')
window.location = "test.html"
load('tools/jquery.js')

// add TOC div
$('body').append('<div id="toc"></div>');

// Build TOC
$("h1, h2, h3").each(function(i) {
    var current = $(this);
    current.attr("id", "title" + i);

    var pos = current.position().top / $("#content").height() * $(window).height();
    $("#toc").append("<a id='link" + i + "' href='#title" + i +
    "' title='" + current.attr("tagName") + "'>" +
    current.html() + "</a>");

    $("#link" + i).css("top", pos);
});    
Envjs.writeToFile(document.documentElement.outerHTML, Envjs.uri('test-toc.html'))

It's a slightly modified version of the script I've found on the web to build a TOC for input html document.

I run it on command line on 3.06Ghz processor using following command:

$ time java -jar t开发者_如何学运维ools/js.jar -opt -1 tools/make-toc.js 
[  Envjs/1.6 (Rhino; U; Mac OS X x86_64 10.7; en-US; rv:1.7.0.rc2) Resig/20070309 PilotFish/1.2.13  ]

real    0m16.554s
user    0m34.131s
sys 0m1.288s

It takes 16 seconds to complete quite a lot for processing. I've also found that the most slow part is Build TOC - it takes most of the time about 10 seconds.

Just to add that input file is more or less small document 23 kilobytes size.

I wonder why it takes so long to run. I would expect it to complete in less than a second.

Question: what is the source of performance loss here? Options I can imagine: 1) Rhino 2) EnvJs 3) JQuery 4) My Script

Any suggestions of other execution environments would be quite appreciated. But need to note that it requires to be integrated into cross-platform development cycle.


Just guess (did not worked with EnvJs and console rhino - only embedded)

A great loss of speed can be caused by "interpreting" mode. (it is context.setOptimizationLevel(-1) at my app)

I had to use it as jQuery main method exceeds 64K Java method size limit.

rhino have "compiling" mode too - which is faster.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜