HTML Preparation code:
AخA
 
1
<!--your preparation HTML code goes here-->
Script Preparation code:
x
 
function createTestElement(threshold = 0.5) {
    const element = document.createElement('div');
    if (Math.random() > 0.8) {
        element.setAttribute('data-test', 'foo');
    }
    while (Math.random() > threshold) {
        element.append(createTestElement(threshold + 0.1));
    }
    return element;
}
const testElements = Array.from({
    length: 100
}, () => createTestElement());
Tests:
  • querySelectorAll

     
    testElements.forEach((el) => {
      const matches = el.querySelectorAll('[data-test]');
      matches.forEach(() => {});
    });
  • querySelector + querySelectorAll

     
    testElements.forEach((el) => {
      if (el.querySelector('[data-test]')) {
        const matches = el.querySelectorAll('[data-test]');
        matches.forEach(() => {});
      }
    });
  • querySelectorAll again (in case of caching)

     
    testElements.forEach((el) => {
      const matches = el.querySelectorAll('[data-test]');
      matches.forEach(() => {});
    });
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    querySelectorAll
    querySelector + querySelectorAll
    querySelectorAll again (in case of caching)

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 months ago)
Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0
Firefox 133 on Linux
View result in a separate tab
Test name Executions per second
querySelectorAll 18178.4 Ops/sec
querySelector + querySelectorAll 38450.6 Ops/sec
querySelectorAll again (in case of caching) 17060.7 Ops/sec