Concatenation vs Array Join vs Array Join Allocate (v22)

Revision 22 of this benchmark created by aikeru on


Preparation HTML

<script>
  var str, str1, i, j;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Concatenation
for (i = 0; i < 10000; i++) {
 str += 'a';
}
ready
Array.prototype.join
var tmp = [];
for (j = 0; j < 10000; j++) {
 tmp.push('a');
}
str2 = tmp.join('');
ready
Array.prototype.join prealloc
var tmp = new Array(10000);
for (j = 0; j < 10000; j++) {
 tmp[j] = 'a';
}
str2 = tmp.join('');
ready

Revisions

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