String concat vs array.join

JavaScript performance comparison

Test case created by Andrew Barrett

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var testString = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam eu diam sit amet augue tempor tincidunt adipiscing sit amet orci. Curabitur scelerisque arcu in lectus interdum blandit. Nunc sit amet fermentum augue. Donec convallis enim vitae urna gravida dapibus. Morbi vulputate faucibus velit nec auctor. In at dolor velit. Aenean feugiat massa nec elit pretium volutpat. Nullam nec justo tristique massa dignissim suscipit. Vestibulum quam enim, varius nec elementum aliquam, aliquet ac turpis. Nulla facilisi. Donec turpis enim, tempus nec eleifend in, dictum nec tellus. Nam sed augue vitae libero cursus vehicula. Duis volutpat congue venenatis. Curabitur ac nunc quam, a adipiscing magna. Donec et est ligula. Donec aliquam sem vitae tellus eleifend feugiat.";
};
</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
+= concat
var ixLoop = 0;
var output = '';

for (; ixLoop < 10000; ixLoop++) {
    output += testString;
}
pending…
array.join
var outputArr = [];
var output = null;
var ixLoop = 0;

for (; ixLoop < 10000; ixLoop++) {
    outputArr.push(testString);
}

output = outputArr.join('');
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. Here’s a list of current revisions for this page:

0 comments

Add a comment