regexp vs indexOf case insensitive (v151)

Revision 151 of this benchmark created by oriman on


Description

Test which is faster - to lowercase the search string or to use regexp

Preparation HTML

<script>
  var str = "hello world!";
  var RX=new RegExp("world",'i');
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Regexp match
str.match(/world/i);
ready
Regexp test
/world/i.test(str)
ready
Regexp dynamic new
(new RegExp("world",'i')).test(str)
ready
Regexp new once
RX.test(str)
ready
indexOf
str.toLowerCase().indexOf("world")!==-1;
ready
indexOf lowercase
str.toLowerCase().indexOf("world".toLowerCase())!==-1;
ready

Revisions

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