javascript array join vs string concat (v14)

Revision 14 of this benchmark created by Steven on


Preparation HTML

<script>
  var myArray = ['adfasdfasdfasdf', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k', 'basdfasdf', 'c', 'd','fsdfasdfasdfasdfasdfasdfasdf','e','sdflkjasdlkfjalksdfjlkasdfjklasdjf9eridixjfaklsdjfg','h','iasdfasdfasdfsdfadsfasdfasdfasdasdf','jsdfd;lfaksdf;alskdjflkj 0q3049304skdlfjlaksdjf lkasdjflkasdf','k'];
</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.