Append string vs join array

JavaScript performance comparison

Revision 17 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var i = 0,
        str = '',
        arr = [],
        w1 = 'brown',
        w2 = 'jumped',
        w3 = 'lazy';
};

Benchmark.prototype.teardown = function() {
    arr.join('');
};
</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
String append #1 (in one go)
str += 'Quick ' + w1 + ' fox ' + w2 + ' over the ' + w3 + ' dog. ';
pending…
String append #2 (one by one)
str += 'Quick ';
str += w1;
str += ' fox ';
str += w2;
str += ' over the ';
str += w3;
str += ' dog. ';
pending…
Array join #2 (in one go)
arr.push('Quick ', w1, ' fox ', w2, ' over the ', w3, ' dog. ');
pending…
Array join #2 (one by one)
arr.push('Quick ');
arr.push(w1);
arr.push(' fox ');
arr.push(w2);
arr.push(' over the ');
arr.push(w3);
arr.push(' dog. ');
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