jQuery vs. Vanilla: 4 - DOM manipulation (remove child content)

JavaScript performance comparison

Test case created by

Preparation code

<script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>

<ul id="comments">
    <li class="comment">1</li>
    <li class="comment">2</li>
    <li class="comment">3</li>
    <li class="comment">4</li>
    <li class="comment">5</li>
    <li class="comment">6</li>
    <li class="comment">7</li>
    <li class="comment">8</li>
    <li class="comment">9</li>
    <li class="comment">10</li>
    <li class="comment">11</li>
    <li class="comment">12</li>
</ul>
    

Preparation code output

<ul id="comments"> <li class="comment">1</li> <li class="comment">2</li> <li class="comment">3</li> <li class="comment">4</li> <li class="comment">5</li> <li class="comment">6</li> <li class="comment">7</li> <li class="comment">8</li> <li class="comment">9</li> <li class="comment">10</li> <li class="comment">11</li> <li class="comment">12</li> </ul>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
jQuery 2.0 empty()
$("#comments").empty();
pending…
vanilla innerHTML()
document.getElementById("comments").innerHTML = null;
pending…
vanilla removeChild()
var c = document.getElementById("comments");
while (c.lastChild) c.removeChild(c.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.

0 Comments