DOM Manipulation

JavaScript performance comparison

Revision 152 of this test case created by P0lip

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<div id="list" style="display:none"></div>
      
<script>
Benchmark.prototype.setup = function() {
  const list = document.getElementById("list");
  const $list = jQuery(list);

};
</script>

Preparation code output

<div id="list" style="display:none"></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
DocumentFragment
var docFragment = document.createDocumentFragment();
var firstDiv = docFragment.appendChild(document.createElement('div'));
firstDiv.textContent = 'No elo';
var secondDiv = firstDiv.appendChild(document.createElement('div'));
secondDiv.textContent = 'Hey there!';
var thirdDiv = secondDiv.appendChild(document.createElement('div'));
thirdDiv.textContent = 'Wazzup?';
secondDiv.remove();
firstDiv.remove();
list.appendChild(docFragment);
pending…
jQuery.html()
$list.html('<div>No elo<div>Hey there!<div>Wazzup?</div></div></div>');
$list.html('<div>No elo</div>');
list.innerHTML = '';
pending…
innerHTML
list.innerHTML = '<div>No elo<div>Hey there!<div>Wazzup?</div></div></div>';
list.innerHTML = '<div>No elo</div>';
list.innerHTML = '';
pending…
createElement with appendChild and .textContent
var firstDiv = list.appendChild(document.createElement('div'));
firstDiv.textContent = 'No elo';
var secondDiv = firstDiv.appendChild(document.createElement('div'));
secondDiv.textContent = 'Hey there!';
var thirdDiv = secondDiv.appendChild(document.createElement('div'));
thirdDiv.textContent = 'Wazzup?';
secondDiv.remove();
firstDiv.remove();
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