Caching vs RegExp Literal

JavaScript performance comparison

Revision 2 of this test case created and last updated

Info

Does storing regular expressions in a variable help?

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var result;
    var expression = /\w+@\w+(?:\.\w+)*/i;
};
</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
literal
result = "j@g.com".match(/\w+@\w+(?:\.\w+)*/i);
pending…
Cached
result = "j@g.com".match(expression);
pending…
Constructor
result = 'j@g.com'.match(RegExp('\\w+@\\w+(?:\\.\\w+)*', 'i'));
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