append vs. innerHTML vs. fragment

JavaScript performance comparison

Revision 22 of this test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="http://3boll.com:3333/js/Js.js"></script>
<script>
Benchmark.prototype.setup = function() {
    var s = [
      $('<a href="#" id="addButt"></a>'),
      $('<a href="#" id="horzButt"></a>'),
      $('<div class="divider"></div>'),
      $('<div id="layoutText">LAYOUT</div>'),
      $('<a href="#" class="vert-active" id="vertButt"></a>'),
      $('<a href="#" id="inspectButton"></a>'),
      $('<div id="inspectText">Inspect</div>'),
      $('<div class="presetPos" id="button">PRESETS</div>'),
      $('<div id="track"></div>')
    ];
   
    var d = document.createElement('div');
    document.body.appendChild(d);
};

Benchmark.prototype.teardown = function() {
    document.body.removeChild(d);
};
</script>

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
jQuery append
$(d).append(s);
pending…
innerHTML
d.innerHTML = s;
pending…
my fragment method
Js.append(d, 'div', 'testid', s);
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