RegExp.test vs. String.search
JavaScript performance comparison
Info
Check performance of simple regex use case of seeing whether a candidate string matches a regex.
Preparation code
<script>
var strings = [];
for (var i = 0; i < 500; ++i) {
strings[i] = "The end of the beginning? Or the beginning of the end?";
}
var regex1 = /beginning/,
regex2 = /(end of).*(end)/,
regex3 = /beginnizg/;
var simpleWrapper = function (regex, string) {
string.search(regex) > -1;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test | Ops/sec | |
---|---|---|
String.search |
|
pending… |
String.match |
|
pending… |
RegExp.test |
|
pending… |
RegExp.exec |
|
pending… |
String.search wrapped |
|
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 Pointy
- Revision 3: published
- Revision 4: published
- Revision 5: published
- Revision 6: published
- Revision 7: published
- Revision 8: published
- Revision 11: published
- Revision 12: published
- Revision 15: published by McGraa
- Revision 16: published by McGraa
- Revision 17: published by McGraa
- Revision 20: published by Auke van Leeuwen
- Revision 21: published by Charmander
- Revision 22: published
- Revision 24: published
- Revision 25: published
0 comments
Comment form temporarily disabled.