exec() vs match() vs test() vs search() (v51)

Revision 51 of this benchmark created on


Description

Tests to determine which function is faster for detecting whether a string matches a regex pattern.

Preparation HTML

<script>
var regex = /regex/;
var str = 'This is a regex string. verto83y4ubvprregovjsherbiouverto83y4ubvprregovjsherbiouverto83y4ubvprregovjsherbiouverto83y4ubvprregovjsherbiouverto83y4ubvprregovjsherbiouverto83y4ubvprregovjsherbiouverto83y4ubvprregovjsherbiouverto83y4ubvprregovjsherbiouverto83y4ubvprregovjsherbiouverto83y4ubvprregovjsherbiouverto83y4ubvprregovjsherbiouverto83y4ubvprregovjsherbiouverto83y4ubvprregovjsherbiouverto83y4ubvprregovjsherbiou';
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
exec()
if (regex.exec(str) !== null) {
 // String matches regex
}
ready
match()
if (str.match(regex) !== null) {
 // String matches regex
}
ready
test()
if (regex.test(str) !== false) {
 // String matches regex
}
ready
search()
if (str.search(regex) !== -1) {
 // String matches regex
}
ready

Revisions

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