Why is v1 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 realized that since I keep the reference to the new object in 'ref', simply assigning that link to an array element is about as fast as assigning a literal value, but it turns out that the link assignment is much slower. Can someone shed some light on this? Anything I can do to improve performance here on V1?
Violin:
http://jsfiddle.net/a0kw9rL1/1/
source share