RegExp vs indexOf

JavaScript performance comparison

Revision 9 of this test case created by Justin Lau

Info

Compare speed of Regex with indexOf for simple string comparison

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 isPresent = new RegExp('[\\?|&]' + 'msn=.');
var url = "zh-hk";

if (/(:?en|zh-(?:hk|cn))/.test(url)) {
  // no op
}
pending…
indexOf
var url = "zh-hk";
var array = ['zh-cn', 'zh-hk', 'en'];

if (-1 !== array.indexOf(url)) {
  // no op
}
pending…

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

Add a comment