string concat vs array join

JavaScript performance comparison

Revision 12 of this test case created by Terry Anastasiadis

Preparation code

<script>
  var arr = ['1st', '2nd', '3rd', '4th'];
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Concat
var text = '',
    i = 0,
    l = arr.length;

for (; i < l; i += 1) {
  text += 'I told you the ' + arr[i] + ' time.<br>';
}
pending…
Join
var text = 'I told you the ' + arr.join(' time.<br>I told you the ') + ' time.';
pending…

Compare results of other browsers

Revisions

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

0 Comments