regexp .test() vs indexOf (v137)

Revision 137 of this benchmark created on


Description

regex.test() vs indexOf()

Setup

var url = Array(200).join("jsperf.com/regexp-vs-indexof/chrome")

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf + string
url.indexOf("chrome") !== 0;
url.indexOf("chrome") !== -1;
ready
.search + regex
url.search(/^chrome/i) === -1;
url.search(/chrome/i) !== -1;
ready
.test
!/^chrome/i.test(url);
/chrome/i.test(url);
ready
.test + brackets
!(/^chrome/i).test(url);
(/chrome/i).test(url);
ready
.search + string
url.search("chrome") !== 0;
url.search("chrome") !== -1;
ready

Revisions

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