Test name | Executions per second |
---|---|
treeWalker with param | 400988.5 Ops/sec |
treeWalker with filter function | 7372.1 Ops/sec |
querySelectorAll | 934566.2 Ops/sec |
<!-- article out start -->
<article>
<!-- article in start -->
<h1>Lorem ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cumque, nostrum.</p>
<!-- article in end -->
</article>
<!-- article out end -->
<!-- article out start -->
<article>
<!-- article in start -->
<h1>Lorem ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cumque, nostrum.</p>
<!-- article in end -->
</article>
<!-- article out end -->
<!-- article out start -->
<article>
<!-- article in start -->
<h1>Lorem ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cumque, nostrum.</p>
<!-- article in end -->
</article>
<!-- article out end -->
const treeWalker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_ELEMENT
);
const list = [];
while (treeWalker.nextNode()) {
list.push(treeWalker.currentNode);
}
const treeWalker = document.createTreeWalker(
document.body,
NodeFilter.SHOW_ALL,
{
acceptNode(node) {
if (node.nodeType === Node.ELEMENT_NODE | Node.TEXT_NODE) {
return NodeFilter.FILTER_ACCEPT;
}
return NodeFilter.FILTER_REJECT;
}
}
);
const list = [];
while (treeWalker.nextNode()) {
list.push(treeWalker.currentNode);
}
const list = document.body.querySelectorAll('*');