String concatenation perf

JavaScript performance comparison

Revision 6 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var items = [{
      html: '<div>test</div>'
  }, {
      html: '<div>test</div>'
  }, {
      html: '<div>test</div>'
  }];

};
</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
join
var html = [];
for (var i = 0, itemLen = items.length; i < itemLen; i++) {
    html.push(items[i].html)
}
var str = html.join('');
pending…
concatenation
var html = '';
for (var i = 0, itemLen = items.length; i < itemLen; i++) {
    html += items[i].html;
}
pending…
optimized array
var html = new Array(items.length)
for (var i = 0, itemLen = items.length; i < itemLen; i++) {
    html[i] = items[i].html;
}
var str = html.join('');
pending…
crazy join
Object.prototype.toString=function(){return this.html};
items.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.

0 Comments