innerHTML vs removeChild

JavaScript performance comparison

Revision 141 of this test case created by empty

Info

what method for empty a element is faster ?

Preparation code

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

function write() {
document.getElementById('box').innerHTML = 'sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df<p>df gsdfg sf g<b>';
}

Preparation code output

function write() { document.getElementById('box').innerHTML = 'sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf gs fs df

df gsdfg sf g'; }

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
removeChildFirst
write();
while (box.firstChild) {
  box.removeChild(box.firstChild);
}
pending…
innerHTML
write();
box.innerHTML = '';
pending…
removeChildLast
while (box.lastChild) {
  box.removeChild(box.lastChild);
}
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