Caching vs RegExp Literal
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
literal |
|
pending… |
Cached |
|
pending… |
Constructor |
|
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:
- Revision 1: published by Aadit M Shah
- Revision 2: published and last updated
- Revision 9: published by Ian Nartowicz
0 comments