RegExp vs indexOf (v29)

Revision 29 of this benchmark created on


Description

Compare speed of Regex with indexOf for simple string comparison

Test runner

Ready to run.

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

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

if ( -1 !== url.indexOf('?msn=') 
|| -1 !== url.indexOf('&msn=') 
|| -1 !== url.indexOf('*msn=') 
|| -1 !== url.indexOf('1msn=') 
|| -1 !== url.indexOf('3msn=') 
|| -1 !== url.indexOf('-msn=') 
|| -1 !== url.indexOf('=msn=') 
) {
  // no op
}
ready

Revisions

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