First occurrence

Benchmark created on


Setup

const s = "abcdef.ciao#ciao2";
const loopSize = 1000;
let start;

Test runner

Ready to run.

Testing in
TestOps/sec
Exec
for (let i = 0; i < loopSize; i++)
	start = /[.#]/.exec(s).index;
ready
Manual scanning
for (let i = 0; i < loopSize; i++)
	for (let j = 0; j < s.length; j++)
		if (s[j] == "#" || s[j] == ".")
		{
			start = j;
			break;
		}
ready
Double indexof
for (let i = 0; i < loopSize; i++)
{
	const index1 = s.indexOf(".");
	const index2 = s.indexOf("#");
	start = index2 === -1 || index1 !== -1 && index1 < index2 ? index1 : index2;
}
ready
Search
for (let i = 0; i < loopSize; i++)
	start = s.search(/[#.]/);
ready

Revisions

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