RegExp test v exec

JavaScript performance comparison

Test case created and last updated

Info

We need to know if a regular expression is being matched within a given string. But how much do you really need to know? Your decision has a significant impact on performance.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var content = "These MadJS meetups are madly informative.";
    var myRe = /(mad\w+) \w+/i; // is a RegExp object!
};
</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
RegExp test
// A RegExp method that tests for a match in a string. It returns true or false.
myRe.test(content);
pending…
RegExp exec
// A RegExp method that executes a search for a match in a string. It returns an array of information.
myRe.exec(content);
pending…
String search
// A String method that tests for a match in a string. It returns the index of the match, or -1 if the search fails.
content.search(myRe);
pending…
String match
// A String method that executes a search for a match in a string. It returns an array of information or null on a mismatch.
content.match(myRe);
 
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

Add a comment