innerHTML vs removeChild

JavaScript performance comparison

Revision 34 of this test case created

Info

what method for empty a element is faster ?

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div id="box"><p>sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g<b>s f</b>s df</p><p>df gsdfg sf g</p></div>
<script>
  var box = document.getElementById("box")
  var backup = box.cloneNode(true)
</script>
<script>
Benchmark.prototype.setup = function() {
    var $box = $(box)
};

Benchmark.prototype.teardown = function() {
    box = backup.cloneNode(true)
};
</script>

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
removeChild
while (box.hasChildren) {
  box.removeChild(box.firstChild)
}
pending…
empty
$box.empty()
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