exec() vs match() vs test() vs search() (v9)

Revision 9 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 = /\/[\d\w]+\/arguments\/[\d\w]+\/reports\/[\d\w]+\/comments\/[\d\w]+\/vote$/;
var str = '/bushtaxcuts/arguments/5EfVm/reports/9oJHN/comments/09iK2/vote';
</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.