Array Clone (v15)

Revision 15 of this benchmark created by Fabio on


Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
Slice
var b = a.slice();
ready
Concat
var b = a.concat();
ready
Concat 2
var b = [].concat(a);
ready
Slice with 0 index
var b = a.slice(0);
ready
Map
var b = a.map(function(e) {
  return (e);
});
ready
Array.apply
var b = Array.apply(this, a);
ready
JSON.parse
var b = JSON.parse( JSON.stringify(a) )
ready

Revisions

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