VT getElementById and querySelector (v43)

Revision 43 of this benchmark created by Vladimir on


Description

This test shows the performance difference between getting the reference to a DOM element by calling getElementById, querySelector

The test only uses one HTML element with the id as the standard expects to only have one unique element with that ID in the DOM. Other than that the created object "node" will contain a collection if we use querySelector or the named element.

Preparation HTML

<div id="parentId"><div id="testid"></div></div>

Setup

parentNode = document.getElementById('parentId');

Test runner

Ready to run.

Testing in
TestOps/sec
getElementById
node = document.getElementById('testid');
 
ready
querySelector
node = document.querySelector('#testid');
 
ready
querySelector relative to parent
node = parentNode.querySelector('#testid');
ready

Revisions

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