string loop

Benchmark created on


Setup

const start = performance.now();

content = "<!-- test comment -->";

Teardown

const end = performance.now();
console.log("DURATION:", end - start, "ms");

Test runner

Ready to run.

Testing in
TestOps/sec
substring
function isStr(str) {
	return content.substring(1, 3) === str;
}

isStr("!--");
ready
loop
function isStr(str) {
    let nextIndex = 0;

    do {
        if (str[nextIndex] !== content[nextIndex + 1]) {
            return false;
        }
        nextIndex++;
    } while (nextIndex < str.length);

    return true;
}


isStr("!--");
ready

Revisions

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