indexOf vs regex.test

Benchmark created on


Description

what detection of substr existence is faster

Preparation HTML

<script>
  var testString = "lorem ipsum dolor",
      test4regex = /rem/,
      test4string = 'rem',
      i = false;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
regex
if (test4regex.test(testString)) {
 i = true;
}
ready
indexOf
if (testString.indexOf(test4string)) {
 i = true;
}
ready

Revisions

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