innerHTML vs removeChild vs jquery.remove (v149)

Revision 149 of this benchmark created 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='box'></div>

Setup

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

Test runner

Ready to run.

Testing in
TestOps/sec
removeChild first
while (box.firstChild) { 
  box.removeChild(box.firstChild); 
}
ready
innerHTML
if (box.firstChild) box.innerHTML = '';
ready
Jquery empty
$(box).empty()
ready
removeChild last
while (box.lastChild) {
  box.removeChild(box.lastChild);
}
ready
removeChild has child
while (box.hasChildNodes()) {
  box.removeChild(box.lastChild);
}
ready

Revisions

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