copy array slice-vs-concat (v11)

Revision 11 of this benchmark created by nick on


Preparation HTML

<script>
  var a = [];

  for (var i = 0; i < 10000; i++)
    a.push('550e8400-e29b-41d4-a716-446655440000');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
concat
var b = a.concat();
ready
while
var i = a.length;
var b = new Array(i);
while (i--) {
  b[i] = a[i];
}
ready
slice no arg
var b = a.slice();
ready
concat new
var b = [].concat(a);
ready
for loop
var len = a.length;
var b = new Array(len);
for(var i=0;i < len; i++) {
  b[i] = a[i];
}
ready
slice 1 arg
var b = a.slice(0);
ready
slice two arg
var b = a.slice(0, a.length);
ready
concat
var b = Array().concat(a);
ready
split()
var b = a.toString().split("");
ready
split() 2
var b = a.join().split("");
ready
map
var b = a.map(function(g){return g;})
ready
filter
var b = a.filter(function(a){return true;});
ready

Revisions

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