JS: For str.indexOf vs Regex (v142)

Revision 142 of this benchmark created on


Description

Testing speed of a indexOf vs Regex when matching smaller substring in larger string.

Preparation HTML

<script>
  var str = "one two three four";
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf
for(var i = 0; i < 1000; i++)
{
var res = str.indexOf("three");
}
ready
Regex
for(var i = 0; i < 1000; i++)
{
var res = /three/i.test(str);
}
ready

Revisions

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