RegExp.exec() vs String.match() vs String.indexOf() (v6)

Revision 6 of this benchmark created on


Setup

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.exec()
smallRegexes.forEach(regex => {
	regex.exec(url);
});
ready
String.match()
smallRegexes.forEach(regex => {
	url.match(regex);
});
ready
RegExp.exec() (global)
smallRegexesG.forEach(regex => {
	regex.exec(url);
});
ready
String.match() (global)
smallRegexesG.forEach(regex => {
	url.match(regex);
});
ready
String.indexOf()
keywords.forEach(keyword => {
	url.indexOf(keyword)
});
ready

Revisions

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