RegExp test / search / match vs. indexOf (v7)

Revision 7 of this benchmark created on


Description

Testing for the existence of characters in a string using Regular Expressions test, search, and match compared to indexOf.

Preparation HTML

<script>
  var str = 'jj.rozario@yahoo.com';
</script>

Setup

var precompiledRegex = /^(([a-zA-Z0-9]+(\.|\_|\-)?)+[a-zA-Z0-9])+@(([a-zA-Z0-9]+(\.|\_|\-)?)+[a-zA-Z0-9])+[.][a-z]{2,6}$/i;

Test runner

Ready to run.

Testing in
TestOps/sec
test
/^(([a-zA-Z0-9]+(\.|\_|\-)?)+[a-zA-Z0-9])+@(([a-zA-Z0-9]+(\.|\_|\-)?)+[a-zA-Z0-9])+[.][a-z]{2,6}$/i.test(str);
ready
search
str.search(/^(([a-zA-Z0-9]+(\.|\_|\-)?)+[a-zA-Z0-9])+@(([a-zA-Z0-9]+(\.|\_|\-)?)+[a-zA-Z0-9])+[.][a-z]{2,6}$/i) > -1;
ready
match
str.match(/^(([a-zA-Z0-9]+(\.|\_|\-)?)+[a-zA-Z0-9])+@(([a-zA-Z0-9]+(\.|\_|\-)?)+[a-zA-Z0-9])+[.][a-z]{2,6}$/i).length > 0;
ready
indexOf
str.indexOf(/^(([a-zA-Z0-9]+(\.|\_|\-)?)+[a-zA-Z0-9])+@(([a-zA-Z0-9]+(\.|\_|\-)?)+[a-zA-Z0-9])+[.][a-z]{2,6}$/i) > -1;
ready
precompiled test
precompiledRegex.test(str);
ready
precompiled search
str.search(precompiledRegex) > -1;
ready
precompiled match
str.match(precompiledRegex).length > 0;
ready
precompiled indexOf
str.indexOf(precompiledRegex) > -1;
ready

Revisions

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