RegExp vs indexOf vs split (v13)

Revision 13 of this benchmark created by weee on


Description

Compare speed of Regex, indexOf and split for simple string comparison.

Setup

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

Test runner

Ready to run.

Testing in
TestOps/sec
Regex
var isPresent = new RegExp('[\\?|&]' + 'msn=.');
if ( isPresent.test(url) ) {
  // no op
}
ready
indexOf
if ( -1 !== url.indexOf('?msn=') || -1 !== url.indexOf('&msn=') ) {
  // no op
}
ready
split
if ( 2 === url.split('?msn=').length || 2 === url.split('&msn=').length ) {
  // no op
}
ready

Revisions

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