Comparison of Array.prototype.join to a for loop with string concatenation

JavaScript performance comparison

Test case created by Roy Tinker

Preparation code

<script>

var TEST_ARR = [];
for (var i=0; i<20000; i++) {
  strings.push(String.fromCharCode(i));
}

</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Array.prototype.join
var result = TEST_ARR.join('');
pending…
For-loop with string concatenation
var result = '';
for (var i = 0, len = TEST_ARR.length; i < len; i++) {
  result += TEST_ARR[i];
}
pending…

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

Compare results of other browsers

0 comments

Add a comment