Duplicate array (slice vs concat)

JavaScript performance comparison

Revision 3 of this test case created by Rob W

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var arr = [];
  for (var i=0; i<12500; i++) {
      arr.push(true, false, true, false, 1, 2, 3, 4);
  }
  // 12500x8 = 1 000 000 elements

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Concat
var res = arr.concat();
pending…
Slice
var res = arr.slice()
pending…
while [ ]
var len = arr.length, i=-1, res = [];
while (++i < len) {
    res[i] = arr[i];
}
pending…
while push
var i = arr.length+1, res = [];
while (--i) {
    res.push(arr[i]);
}
pending…

Compare results of other browsers

Revisions

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

0 Comments