Why is [].concat() faster than Array.prototype.concat()?
Array.prototype.concat
needs to be resolved in every loop. If you would lookup the function only once, you'll see different results. This may vary depending on the implementation of the runtime though.
var a = b = c = [1,2,3,4,5];
// Array.prototype.concat
console.time('t1');
var apc = Array.prototype.concat;
for (i = 0; i < 1000000; i++) {
apc.call([], a, b, c);
};
console.timeEnd('t1')
// [].concat
console.time('t2');
for (i = 0; i < 1000000; i++) {
[].concat(a, b, c);
};
console.timeEnd('t2')
// They're the same:
console.log(Array.prototype.concat === [].concat);
To get more accurate results, use a proper benchmarking library (eliminates warm up time for example).