Scoped queryselector

Benchmark created on


Description

Checks whether scoped queryselectors are faster than document queryselectors

Setup

function button(text) {
	const d = document.createElement("button");
	d.textContent = text;
	return d;
}

function span(children) {
	const d = document.createElement("span");
	d.append(...children);
	return d;
}

for (let i = 0; i < 1000; i++) {
	document.body.append(span([button('1'), button('1')]));
}

Teardown

document.body.querySelectorAll('span').forEach((e) => e.remove());

Test runner

Ready to run.

Testing in
TestOps/sec
Document querySelector
document.querySelectorAll('button');
ready
Queryselector inside first span
document.body.firstChild.querySelectorAll('button');
ready

Revisions

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