removeChildren
JavaScript performance comparison
Info
From http://elv1s.ru/files/html+css/removeChildren.html
Test various ways of emptying an element of child nodes
Preparation code
<div id="container" style="display:none">
</div>
<script>
Benchmark.prototype.setup = function() {
var container = document.getElementById('container'),
proto = addelements(document.createDocumentFragment());
function addelements(proto) {
var i = 200,
p, j, span;
while (i--) {
p = document.createElement('p');
j = 5;
while (j--) {
span = document.createElement('span');
span.appendChild(document.createTextNode(i * j + 'yada-yada'));
p.appendChild(span);
};
proto.appendChild(p);
};
return proto;
};
function prepare() {
container.appendChild(proto.cloneNode(false));
};
};
Benchmark.prototype.teardown = function() {
if (container.childNodes.length) {
throw "Container was not emptied!";
}
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
innerHTML |
|
pending… |
textContent |
|
pending… |
removeFirstChild |
|
pending… |
remove lastChild |
|
pending… |
remove by count |
|
pending… |
forEach |
|
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:
- Revision 1: published by Nikita Vasilyev and last updated
- Revision 2: published by Thomas Aylott and last updated
- Revision 3: published by Mathias Bynens
- Revision 7: published
- Revision 8: published by Francis Avila
0 comments