Matches: Comma selector vs loop over selectors (v4)

Revision 4 of this benchmark created on


Preparation HTML

<div id="el"></div>
<div id="el2" class="test"></div>

Setup

window.SELECTORS = [".test"];
for (let i = 0; i < 10000; i++) {
	SELECTORS.push(".x" + crypto.randomUUID());
}
window.BIG_SELECTOR = SELECTORS.join(", ");

let el = document.getElementById("el");
let el2 = document.getElementById("el2");

Test runner

Ready to run.

Testing in
TestOps/sec
Comma-separated selector
el.matches(SELECTORS.join(", "));
ready
Loop
SELECTORS.some(sel => el.matches(sel));
ready
Comma-separated with short circuit
el2.matches(SELECTORS.join(", "));
ready
Loop with short-circuit
SELECTORS.some(sel => el2.matches(sel));
ready
Prepared comma-separated selector
el.matches(BIG_SELECTOR);
ready
Prepared comma-separated selector with short circuit
el2.matches(BIG_SELECTOR);
ready

Revisions

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