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

Revision 83 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 = '00000000-0000-1000-8080-808080808080';
</script>

Setup

var precompiledRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;

Test runner

Ready to run.

Testing in
TestOps/sec
test
/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str);
ready
search
str.search(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i) > -1;
ready
match
str.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i).length > 0;
ready
indexOf match
str.indexOf('00000000-0000-1000-8080-808080808080') > -1;
ready
precompiled test
precompiledRegex.test(str);
ready
precompiled search
str.search(precompiledRegex) > -1;
ready
precompiled match
str.match(precompiledRegex).length > 0;
ready
indexOf no match
str.indexOf('00000000-0000-1000-8080-808080808090') > -1;
ready

Revisions

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