innerHTML vs removeChild

JavaScript performance comparison

Revision 68 of this test case created

Info

what method for empty a element is faster ?

Preparation code

<div id='box'>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></div>

Preparation code output

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
while (box.firstChild) {
  box.removeChild(box.firstChild);
}
pending…
innerHTML
box.innerHTML = '';
pending…
removeChildLast
while (box.lastChild) {
  box.removeChild(box.lastChild);
}
pending…
removeChildFirst - hasChildNodes
while (box.hasChildNodes()) {
  box.removeChild(box.firstChild);
}
pending…
removeChildLast - hasChildNodes
while (box.hasChildNodes()) {
  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