Cloning Arrays

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

<script>
  var a = [];
  for (var i = 0; i < 2000; i++) {
   a[i] = i;
  }
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Slice
var b = a.slice();
pending…
Concat
var b = a.concat();
pending…
Concat 2
var b = [].concat(a);
pending…
Slice with 0 index
var b = a.slice(0);
pending…
Map
var b = a.map(function(e) {
    return (e);
});
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. Here’s a list of current revisions for this page:

0 comments

Add a comment