RegExp.exec() vs String.match() (v5)

Revision 5 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()
smallRegexesG.forEach(regex => {
    for(let m = regex.exec(url); m !== null; m = regex.exec(url)) {
     //console.log(m);
    }
});
ready
String.replace()
smallRegexesG.forEach(regex => {
    url.replace(regex, function(match, g1, g2) {
      //console.log(match, g1, g2);
    });
});
ready

Revisions

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