StartsWith - RegExp vs lastIndexOf (v14)

Revision 14 of this benchmark created by Andrew on


Description

Compare speed of Regex with lastIndexOF for startsWith

Test runner

Ready to run.

Testing in
TestOps/sec
Regex
var testStr = 'Some';
var isPresent = new RegExp('^' + testStr);
var str = "Some string for testing";

if (isPresent.test(str)) {
  // no op
}
ready
lastIndexOf
var testStr = 'Some';
var isPresent = new RegExp('^' + testStr);
var str = "Some string for testing";

if (-1 !== str.lastIndexOf(testStr, 0)) {
  // no op
}
ready

Revisions

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