regexp vs indexOf (v94)

Revision 94 of this benchmark created by SpeedySan on


Description

Usually .match and .indexOf are used in condition statements where the result of both of these has to be converted to a boolean. Since one of these returns an array (or null) and another returns a number, it would be more useful if we also included the cost of converting these results to a boolean in the final result.

Also, .match returns either an array or a null, which have different conversion costs. So added negative tests as well.

Preparation HTML

<script>
  var str = "hello world!";
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Regexp Positive
!!str.match(/world/);
ready
indexOf Positive
str.indexOf("world")>-1;
ready
Regexp Negative
!!str.match(/nomatch/);
ready
indexOf Negative
str.indexOf("nomatch")>-1;
ready

Revisions

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