querySelector vs getElementById (v2)

Revision 2 of this benchmark created on


Description

Checking how much faster is document.getElementById vs document.querySelector

Preparation HTML

<div id="foo" class="bar"></div>

Test runner

Ready to run.

Testing in
TestOps/sec
getElementById
document.getElementById('foo')
ready
querySelector - by id
document.querySelector('#foo')
ready
querySelector - by class
document.querySelector('.bar')
ready
getElementsByTagName
document.getElementsByTagName('div')[0];
ready

Revisions

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