"+=" operator vs array concat

JavaScript performance comparison

Test case created

Preparation code

<div id="container"></div>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
"+=" operator
var html = '';
html += '<nav></nav>';
html += '<div id="content">';
for (var i; i < 100; i++) {
    html += '<h1>' + i + ',</h1>';
}
html += '</div><div id="footer"></div>';
document.getElementById('container').innerHTML = html;
pending…
array concat
var arr = [];
arr.push('<nav></nav>');
arr.push('<div id="content">')
for (var i; i < 10; i++) {
    arr.push('<h1>' + i + ',</h1>');
}
arr.push('</div><div id="footer"></div>');
document.getElementById('container').innerHTML = arr;
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