innerHTML vs removeChild vs jquery.empty (v138)

Revision 138 of this benchmark created by DanMan on


Description

what method for empty a element is faster ?

Preparation HTML

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

Setup

var box = document.getElementById('box');
    for (var i=0;i<1000;i++){
        var c   = document.createElement('div');
        c.textContent = 'siodfj'+Date.now();
        box.appendChild(c);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
removeChild reversed
for (var i = box.childNodes.length - 1; i >= 0; i--) {
  box.removeChild(box.childNodes[i]);
}
 
ready
innerHTML
box.innerHTML = '';
ready
jQuery empty
$(box).empty()
ready
cloneNode
var dupNode = box.cloneNode(false);
box.parentNode.replaceChild(dupNode, box);
 
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.