getElementByTagName('*').filter vs. querySelectorAll for Prefix

JavaScript performance comparison

Revision 244 of this test case created by Kevin McCormick

Preparation code

<p id="foo-bar1">Contents</p>
<p id="foo-bar2">Contents</p>
<p id="foo-bar3">Contents</p>
<p id="foo-bar4">Contents</p>
<p id="foo-bar5">Contents</p>
<p id="foo-bar6">Contents</p>
    

Preparation code output

<p id="foo-bar1">Contents</p> <p id="foo-bar2">Contents</p> <p id="foo-bar3">Contents</p> <p id="foo-bar4">Contents</p> <p id="foo-bar5">Contents</p> <p id="foo-bar6">Contents</p>

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
getElementByTagName(*).filter
var bar = Array.from(document.getElementByTagName("*")
  .filter(e = > e.hasAttribute("id") ?
                e.getAttribute("id").startsWith("foo-") : false)
pending…
querySelectorAll
var bar = Array.from(document.querySelectorAll(`*[id ^= "foo-"]`));
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

Contents

Contents

Contents

Contents

Contents

Contents