startsWith vs indexOf

Benchmark created on


Setup

var string = "lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet lorem ipsum dolor sit amet";

Test runner

Ready to run.

Testing in
TestOps/sec
startsWith 1 char
if (string.startsWith('l')) return true;
ready
startsWith 4 chars
if (string.startsWith('lore')) return true;
ready
indexOf 1 char
if (string.indexOf('l') === 0) return true;
ready
indexOf 4 chars
if (string.indexOf('lore') === 0) return true;
ready

Revisions

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