querySelectorAll vs getElementById (v8)

Revision 8 of this benchmark created by Thomas Fuchs on


Preparation HTML

<p id="foo">bar</p>
<script>
  var IDENTIFIER = /^#[a-zA-Z-_]+$/;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
querySelectorAll
var result = document.querySelectorAll('#foo');
ready
getElementById
var result = document.getElementById('foo');
ready
on demand
var id = '#foo',
    result = IDENTIFIER.test(id) ? [document.getElementById(id.substr(1))] : document.querySelectorAll(id);
ready

Revisions

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