RegExp vs indexOf (v18)

Revision 18 of this benchmark created by Thiago Nobre on


Description

Compare speed of Regex with indexOf for simple string comparison

Setup

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

Test runner

Ready to run.

Testing in
TestOps/sec
Regex
if (isPresent.test(url)) {
  // no op
}
ready
indexOf
if (-1 !== url.indexOf('?msn=') || -1 !== url.indexOf('&msn=')) {}
ready

Revisions

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