Find if contains char

Benchmark created on


Setup

const s = "abcdefghij.pippo#pluto";
let ris;

Test runner

Ready to run.

Testing in
TestOps/sec
Regex test
for (let i = 0; i < 1000; i++)
	ris = /[.#]/.test(s);
ready
includes
for (let i = 0; i < 1000; i++)
{
	ris = false;
	for (let j = 0; j < s.length; j++)
		if ("#.".includes(s[j]))
		{
			ris = true;
			break;
		}
}
	
ready
Includes fixed string
const c = "#.";
for (let i = 0; i < 1000; i++)
{
	ris = false;
	for (let j = 0; j < s.length; j++)
		if (c.includes(s[j]))
		{
			ris = true;
			break;
		}
}
	
ready
Manual if
for (let i = 0; i < 1000; i++)
{
	ris = false;
	for (let j = 0; j < s.length; j++)
		if (s[j] === "#" || s[j] === ".")
		{
			ris = true;
			break;
		}
}
	
ready
Inverse includes
for (let i = 0; i < 1000; i++)
	ris = s.includes("#") || s.includes(".");
ready
Inverse includes bigger
for (let i = 0; i < 1000; i++)
	ris = s.includes(" ") || s.includes(">") || s.includes("+") || s.includes("~");
ready
Regex test bigger
for (let i = 0; i < 1000; i++)
	ris = /[ >+~]/.test(s);
ready

Revisions

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