querySelector vs getElementsByClassName[0]

Benchmark created by Benjamin De Cock on


Preparation HTML

<p class=foo>foo</p>
<p class=foo>bar</p>
<p class=foo>baz</p>

Test runner

Ready to run.

Testing in
TestOps/sec
querySelector
document.querySelector(".foo")
ready
getElementsByClassName
document.getElementsByClassName("foo")[0]
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Benjamin De Cock on