Concatenation vs Array Join (v17)

Revision 17 of this benchmark created on


Preparation HTML

<script>
  var i,
      str = '',
      tmp = [],
      tmp2 = [],
      cnt = 10000,
      push = Array.prototype.push,
      join = Array.prototype.join;

for (i = 0; i < cnt; i++) {
 push.call(tmp2, 'a');
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Concatenation
for (i = 0, str = ''; i < cnt; i++) {
 str += 'a';
}
ready
Array.prototype.join 1
for (i = 0, tmp.length = 0; i < cnt; i++) {
 push.call(tmp, 'a');
}

str = join.call(tmp, '');
ready
Array.prototype.join 2
for (i = 0, tmp.length = 0; i < cnt; i++) {
 tmp[i] = 'a';
}

str = join.call(tmp, '');
ready
Array.prototype.join 3
str = join.call(tmp2, '');
ready

Revisions

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