A
AKS
Hi! Here's a small test case (for Firefox):
var o = {
p: {
func: function () {},
},
test: function () {
var msg = [];
var d = new Date;
var i = 1000000;
var f = this.p.func;
while (i--) {
f();
};
msg[0] = (new Date) - d; // ~ 2700 ms
d = new Date;
i = 1000000;
while (i--) {
this.p.func();
};
msg[1] = (new Date) - d; // ~ 900 ms
console.log(msg.join('\n'));
}
};
o.test();
The first iteration takes more time than the second one. But the
second one performs property access (two dot operators)! Can someone
shed some light on this behavior?
Here's my thoughts:
When this value is null then null must be replaced with a global
value. And search for the global value (by the JavaScript engine)
takes too much time.
var o = {
p: {
func: function () {},
},
test: function () {
var msg = [];
var d = new Date;
var i = 1000000;
var f = this.p.func;
while (i--) {
f();
};
msg[0] = (new Date) - d; // ~ 2700 ms
d = new Date;
i = 1000000;
while (i--) {
this.p.func();
};
msg[1] = (new Date) - d; // ~ 900 ms
console.log(msg.join('\n'));
}
};
o.test();
The first iteration takes more time than the second one. But the
second one performs property access (two dot operators)! Can someone
shed some light on this behavior?
Here's my thoughts:
When this value is null then null must be replaced with a global
value. And search for the global value (by the JavaScript engine)
takes too much time.