StartsWith - RegExp vs lastIndexOf

JavaScript performance comparison

Revision 14 of this test case created by Andrew

Info

Compare speed of Regex with lastIndexOF for startsWith

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

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

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

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

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Comment form temporarily disabled.

Add a comment