RegExp test / search / match vs. indexOf

Benchmark created by Tom Doan 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 = 'Hello, world.';
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
test
/o, w/.test(str);
ready
search
str.search(/o, w/) > -1;
ready
match
str.match(/o, w/).length > 0;
ready
indexOf
str.indexOf('o, w') > -1;
ready

Revisions

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