innerHTML vs removeChild (v135)

Revision 135 of this benchmark created on


Description

what method for empty a element is faster ?

Preparation HTML

<div id='box'></div>

Setup

var box = document.getElementById('box');
    box.innerHTML = '<div><div class="aaa"></div><div class="aaa"></div><div class="aaa"></div></div><div><div class="aaa"></div><div class="aaa"></div><div class="aaa"></div></div><div><div class="aaa"></div><div class="aaa"></div><div class="aaa"></div></div><div><div class="aaa"></div><div class="aaa"></div><div class="aaa"></div></div>';

Test runner

Ready to run.

Testing in
TestOps/sec
removeChild first
while (box.firstChild) {
  box.removeChild(box.firstChild);
}
ready
innerHTML
box.innerHTML = '';
ready
removeChild last
while (box.lastChild) {
  box.removeChild(box.lastChild)
}
 
ready
removeChild last2
var l;
while (l=box.lastChild) {
  box.removeChild(l)
}
 
ready

Revisions

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