jquery html vs empty vs innerHTML

JavaScript performance comparison

Revision 19 of this test case created by Joshua Piccari

Preparation code

<ul id="my_list">
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
  <p>
    aaa
    <span>
      bbb
    </span>
  </p>
</ul>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  $(function() {
    var i = 0,
        $ul = $('#my_list'),
        $li = $('<li />').html('list item');

    while (i < 100) {
      $ul.append($li.clone());
      i++;
    }
  });
</script>
<script>
Benchmark.prototype.setup = function() {
    var elem = document.getElementById('my_list'),
    $elem = $(elem);
};
</script>

Preparation code output

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

    aaa bbb

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
innerHTML
elem.innerHTML = '';
pending…
jquery html
$elem.html('');
pending…
jquery empty
$elem.empty();
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