RegExp vs indexOf

JavaScript performance comparison

Revision 15 of this test case created

Info

Compare speed of Regex with indexOf for simple string comparison

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var isPresent = new RegExp('MSN', 'i');
    var url = 'http://create.leadid.local?pid=2iuegu12&msn=23uigqwud';
};
</script>

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
if (isPresent.test(url)) {}
pending…
indexOf
if (-1 !== url.toLowerCase().indexOf('MSN'.toLowerCase())) {}
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