Why javascript binding's performance is so low?

I created a project use cocos2d-x & js-binding, wrote it in the main.js

function testIt() {
    var max = 900;
    var start = new Date().getTime();
    for (var i = 0; i < max; ++i) {
        for (var j = 0; j < max; ++j) {}
    }
    cc.log("cost:"+(new Date().getTime() - start));
}
testIt();

It prints:

cost:821

but if I test it in the chrome’s developer tool,it only takes 9ms.
Is the cost of binding? Or where I made a mistake?

yes, I met same problem. for the processing of an array with a lot of elements, it is very very slow.
I think chrome/nodejs V8 is realtime compiling and optimise a lot has a better performance than SpiderMonkey.
My solution is avoiding Intensive computing in javascript and using c++ do the Intensive computing then construct jsb to get the computing result

Thanks for your reply, John! and It seems to be the only way can improve the performance.

@yonghua,
Did you build your JS project in Release mode? Which platform did you test on?

James Chen wrote:

@yonghua,
Did you build your JS project in Release mode? Which platform did you test on?

I tested on release mode ad hoc on ipod iphone, same result

@James
No,I built it in Debug mode. As John said,There is no differences.

Is it possible that SpiderMonkey is not optimizing empty arrays ?
And V8 detects that it is an empty array and it skip it?

@Ricardo Quesada
Sorry,But if I do something in the loop,it also slow!

Ricardo Quesada wrote:

Is it possible that SpiderMonkey is not optimizing empty arrays ?
And V8 detects that it is an empty array and it skip it?

father of cocos2d

glad to meet you:)

thanks for your great cocos2d

yes, JS is slow when comes to looping, JIT helps, but not much, this is limited by the cpu power.

avoid heavy looping in JS logics, instead, offload heavy calculation to C++ function, and bind to it