JS: For str.indexOf vs Regex (v119)

Revision 119 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 = "mozilla/5.0 (compatible; msie 9.0; windows nt 6.1; wow64; trident/5.0; slcc2; .net clr 2.0.50727; .net clr 3.5.30729; .net clr 3.0.30729; media center pc 6.0; .net4.0c; .net4.0e)";
</script>

Test runner

Ready to run.

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

Revisions

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