jquery append() vs html()

JavaScript performance comparison

Revision 4 of this test case created by tuanquynet

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="divA"></div>

      
<script>
Benchmark.prototype.setup = function() {
  var total = 100;
  
  var list = [];
  for (var i = 0; i < total; i++) {
    list.push("<p>Some html</p>");
  }
  

};

Benchmark.prototype.teardown = function() {
  $("#divA").html("");

};
</script>

Preparation code output

<div id="divA"></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
append()
var $divA = $("#divA");
for (var i = 0; i < total; i++) {
  $divA.append('some html');
}
pending…
html()
var htmlStr = "";
for (var i = 0; i < total; i++) {
  htmlStr += 'some html';
}
$("#divA").html(htmlStr);
pending…
html()
var htmlStr = [];
for (var i = 0; i < total; i++) {
  htmlStr.push('some html');
}
$("#divA").html(htmlStr.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