javascript array join vs string concat (v4)

Revision 4 of this benchmark created on


Preparation HTML

<script>
  var myArray = ['a', 'b', 'c', 'd','f','e','g','h','i','j','k','l','m'];
</script>

Test runner

Ready to run.

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

output = tmp.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

Revisions

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