Cloning Arrays (v22)

Revision 22 of this benchmark created 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 with 0 index
var b = a.slice(0);
ready
Concat 2
var b = [].concat(a);
ready
Spread
var b = [...a]
ready
Slice
var b = a.slice();
ready
For
var b = [];
for(var i = 0; i < a.length; i++) {
    b[i] = a[i];
}
ready
For 2
var len = a.length;
var b = new Array(len);
for(var i = 0; i < len; i++) {
   b[i+0] = a[i];
}
ready
Map
var b = a.map(function(e) {
    return (e);
});
ready
Concat
var b = a.concat();
ready

Revisions

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