javascript array join vs string concat (v11)

Revision 11 of this benchmark created on


Preparation HTML

<script>
  var alphabet = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
  var alphatmp = [];
  
  for(i=0;i<200;i++)
      alphatmp.push(alphabet);
  
  var str_to_split = alphatmp.join(',');
  var myarray = str_to_split.split(',');
  
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
array join (use push)
var output = '',
    i;
output = myArray.join('');
ready
array join (use length)
var output = '',
    tmp = [],
    i;
for (i = 0; i < myArray.length; i++) {
  tmp[tmp.length] = myArray[i];
}

output = tmp.join('');
ready
string concat
var output = '',
    i;
for (i = 0; i < myArray.length; i++) {
  output += myArray[i];
}
ready
array join (use length) - optimized
var output = '',
    tmp = [],
    i;
for (i = 0, il = myArray.length; i < il; i++) {
  tmp[tmp.length] = myArray[i];
}

output = tmp.join('');
ready
string concat - optimized
var output = '',
    i;
for (i = 0, il = myArray.length; i < il; i++) {
  output += myArray[i];
}
ready
array join (use push) - optimized
var output = '',
    tmp = [],
    i;
for (i = 0, il = myArray.length; i < il; i++) {
  tmp.push(myArray[i]);
}

output = tmp.join('');
ready

Revisions

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