querySelector vs querySelectorAll vs getElementById vs getElementsByClassName vs getElementsByTagName

JavaScript performance comparison

Revision 69 of this test case created by

Preparation code

<p id="foo" class="foo">
  bar

<ul>
   <li><a href="#" class="colored" colored>Page 1</a></li>
   <li><a href="#" class="colored" colored>Page 2</a></li>
   <li><a href="#" class="colored" colored>Page 3</a></li>
   <li><a href="#" class="colored" colored>Page 4</a></li>
</ul>

</p>
    

Preparation code output

<p id="foo" class="foo"> bar <ul> <li><a href="#" class="colored" colored>Page 1</a></li> <li><a href="#" class="colored" colored>Page 2</a></li> <li><a href="#" class="colored" colored>Page 3</a></li> <li><a href="#" class="colored" colored>Page 4</a></li> </ul> </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
querySelectorAll
document.querySelectorAll("[colored]");
pending…
getElementsByClassName
document.getElementsByClassName('colored');
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

bar