array indexOf vs array includes vs regex match (v3)

Revision 3 of this benchmark created on


Setup

const haystack = Array.from({ length: 20 }, (_, i) => `word${i}`).join("");
const needle = "word19";
const needleRegex = new RegExp(needle);

Test runner

Ready to run.

Testing in
TestOps/sec
string.includes
haystack.includes(needle);
ready
regex.test
needleRegex.test(haystack);
ready
string.indexOf
haystack.indexOf(needle) !== 1;
ready

Revisions

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