innerHTML vs createElement test

JavaScript performance comparison

Revision 75 of this test case created by

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="container">
</div>
      
<script>
Benchmark.prototype.setup = function() {
  document.getElementById('container').innerHTML = '';

};

Benchmark.prototype.teardown = function() {
  document.getElementById('container').innerHTML = '';

};
</script>

Preparation code output

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

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
javascript
      circle = document.createElementNS("http://www.w3.org/2000/svg", "circle");
      circle.setAttributeNS(null, "r", "25%");
      circle.setAttributeNS(null, "cx", "50%");
      circle.setAttributeNS(null, "cy", "50%");
      circle.setAttributeNS(null, "stroke-dasharray", "" + (50 * Math.PI) + "%");
      circle.setAttributeNS(null, "stroke-dashoffset", "" + (50 * Math.PI) + "%");
      svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
      dummyCircle = circle.cloneNode(true);
      svg.appendChild(circle);
      svg.appendChild(dummyCircle);
      div = $("<div></div>");
      p = $("<p></p>");
      p.attr("id", "time-elapsed");
      div.attr("id", "ct-circle-container");
      div.append(p);
      div.append(svg);

$('#container').append(div)
pending…
jquery
      circles = $('<div id="ct-circle-container"><p id="time-elapsed"></p><svg>' + ((function() {
        var _i, _results;
        _results = [];
        for (_i = 1; _i <= 2; _i++) {
          _results.push('<circle r="25%" cx="50%" cy="50%" stroke-dasharray="' + 50 * Math.PI + '%" stroke-dashoffset="' + 50 * Math.PI + '%"></circle>');
        }
        return _results;
      })()));

$('#container').append(circles)
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