RegExp vs indexOf (v33)

Revision 33 of this benchmark created on


Description

Compare speed of Regex with indexOf for simple string comparison

Setup

var regex = new RegExp('[\\?|&]' + 'msn=.');
    var containStr = '?msn=';

Test runner

Ready to run.

Testing in
TestOps/sec
Regex
var url = "http://create.leadid.local?pid=2iuegu12&msn=23uigqwud";

if (regex.test(url)) {
  // no op
}
ready
indexOf
var url = "http://create.leadid.local?pid=2iuegu12&msn=23uigqwud";

if (url.indexOf(containStr) !== -1) {
  // no op
}
ready

Revisions

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