Concat vs Splice (v3)

Revision 3 of this benchmark created on


Description

Compare repeated concat to splice

Test runner

Ready to run.

Testing in
TestOps/sec
Concat
var a = [];
for(var i = 0; i < 1000; i++) {
  a = a.concat([i]);
}
ready
Splice
var a = [];
for(var i = 0; i < 1000; i++) {
   Array.prototype.splice.apply(a, [i, 0].concat([i]));
}
ready
Sized Array
var a = new Array(1000);
for(var i = 0; i < 1000; i++) {
   Array.prototype.splice.apply(a, [i, 0].concat([i]));
}
ready
Splice without concat
var a = [];
for(var i = 0; i < 1000; i++) {
   Array.prototype.splice.call(a, i, 0, i);
}
ready
Concat (Join array with values)
var a = [];
for(var i = 0; i < 1000; i++) {
  a = a.concat(i);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.