Case Insensitive String Search

Benchmark created on


Preparation HTML

<label id="vector-toc-collapsed-button" for="vector-toc-collapsed-checkbox" role="button" title="Table of Contents">Toggle the table of contents</label>

Test runner

Ready to run.

Testing in
TestOps/sec
RegExp
function escapeRegExp(string) {
	return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
}


function getElement() {
	return document.querySelector("label")
}

function compute(element) {
	let text = element.textContent;
	let title = element.getAttribute("title");
	return (new RegExp(escapeRegExp(text), "gi").test(title) ||
			new RegExp(escapeRegExp(title), "gi").test(text))
}

compute(getElement())
ready
Includes LowerCase
function getElement() {
	return document.querySelector("label")
}

function compute(element) {
	let text = element.textContent.toLowerCase();
	let title = element.getAttribute("title").toLowerCase();
	return (text.includes(title) || title.includes(text))
}

compute(getElement())
ready

Revisions

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