Why is v1 so much slower than v2?
v1 --
var foo = function (a,b,c) {
this.a=a; this.b=b; this.c=c;
}
var pcs = new Array(32);
for (var n=32; n--;) {
ref = new foo(1,2,3)
pcs[n] = ref; //*****
}
v2 --
var foo = function (a,b,c) {
this.a=a; this.b=b; this.c=c;
}
var pcs = new Array(32);
for (var n=32; n--;) {
ref = new foo(1,2,3)
pcs[n] = 1; //*****
}
I figured that since I'm holding a reference to the new object in 'ref', that simply assigning that reference to an element in the array would be about as fast as assigning a literal value, but it turns out that assigning the reference is considerably slower. Can anyone shed some light on this? Anything I can do to improve the performance here on V1?
Fiddle:
for"header",n--. If it returns0, the loop terminates.0