RegExp vs indexOf (v4)

Revision 4 of this benchmark created by Sreejith on


Description

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

Test runner

Ready to run.

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

if (isPresent.search(url)) {
  // no op
}
ready
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
}
ready

Revisions

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