AKS <ak******@yandex.ruwrites:
Are you sure that there's no computation of global value? After I've
looked at this code (http://lxr.mozilla.org/seamonkey/source/js/src/
jsinterp.c#738), I had doubts.
<thisisn't scoped like other variables. it's always directly set to
either the global object, or a new object or whatever object is the
reciever of the message/method call. And in case of the global object,
that *can* be determined at parse/compile time.
Not that that code does anything like that (if I read it correctly), but
in any case, that code will probably (handwave, cough, cough) take about
as much time (or less) per nested scope as resolving each object in a
thing.that.such.bla() call would.
>If you're worried about speed, fix your code so that you don't have
to do a million function calls, all at once.
It's not production code. It should be considered as an example for
the educational purposes.
What would be far more interesting from a practical POV is how much
overhead a method/function call adds when you're actually doing some
reasonable amount of work in the call.
Check the times on this example (not that counting to 400 is such a good
test, but it's just to give an indication):
if (!console) console = { log: print }; // for spidermonkey shell
var o = {
p: {
func: function () { for (var k = 0; k < 400; k++) { } },
},
test: function () {
var msg = [];
var d = new Date;
var i = 10000;
var f = this.p.func;
while (i--) {
f();
};
msg[0] = (new Date) - d; // ~ 170 ms
d = new Date;
i = 10000;
while (i--) {
this.p.func();
};
msg[1] = (new Date) - d; // ~ 170 ms
d = new Date;
i = 10000;
while (i--) {
for (var k = 0; k < 400; k++) {
;
}
};
msg[2] = (new Date) - d; // ~ 169 ms
console.log(msg.join('\n'));
}
};
o.test();
--
Joost Diepenmaat | blog:
http://joost.zeekat.nl/ | work:
http://zeekat.nl/