RegExp.test() vs String.indexOf() vs String.match() vs String.matchAll() (v3)

Revision 3 of this benchmark created on


Setup

const regex = /(?=.*page)(?=.*a=1)(?=.*c=3)/;
const regexG = /(?=.*page)(?=.*a=1)(?=.*c=3)/g;
const smallRegexes = [/page/, /a=1/, /c=3/];
const smallRegexesG = [/page/g, /a=1/g, /c=3/g];
const keywords = ['page', 'a=1', 'c=3'];
const url = 'example.com/page/the-cool-page?c=3&a=1&b=2';

Test runner

Ready to run.

Testing in
TestOps/sec
RegExp.test()
regex.test(url);
ready
String.indexOf()
keywords.every(keyword => url.indexOf(keyword) !== -1);
ready
String.match() (looped)
smallRegexes.every(regex => {
	url.match(regex);
});
ready
String.matchAll()
smallRegexesG.every(regex => {
	url.matchAll(regex);
});
ready
String.match() (long regex)
url.match(regex);
ready
String.matchAll() (long regex)
url.matchAll(regexG);
ready

Revisions

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