RegExp vs indexOf

JavaScript performance comparison

Revision 4 of this test case created by Sreejith

Info

Compare speed of Regex with ( indexOf + toLowerCase ) for simple string comparison

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Regex
var isPresent = new RegExp('[\\?|&]' + 'msn=.');
var url = "http://create.leadid.local?pid=2iuegu12&msn=23uigqwud";

if (isPresent.search(url)) {
  // no op
}
pending…
indexOf + toLowerCase
var isPresent = new RegExp('[\\?|&]' + 'msn=.');
var url = "http://create.leadid.local?pid=2iuegu12&msn=23uigqwud";

if (-1 !== url.indexOf('?msn=') || -1 !== url.toLowerCase().indexOf('&msn=')) {
  // no op
}
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment