innerHTML vs removeChild(A slightly lighter html)

JavaScript performance comparison

Revision 108 of this test case created by prashant sheoran


what method for empty a element is faster ?

Preparation code

<div id='box'></div>
Benchmark.prototype.setup = function() {
    var box = document.getElementById('box');
    box.innerHTML = 'sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df'

Benchmark.prototype.teardown = function() {
    box.innerHTML = 'sf g<b>s f</b>s df<p>df gsdfg sf g<b>s f</b>s df'

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
while (box.firstChild) {
box.innerHTML = '';

Compare results of other browsers


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:

1 comment

prashant sheoran (revision owner) commented :

Edited orginal Testcase to show that innerHtml is slower even with a small document fragment.

Comment form temporarily disabled.

Add a comment