Javascript compiled regex

JavaScript performance comparison

Test case created by Dan Andreescu

Info

Just what exactly does .compile() do?

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var someText = "(1234,12451,32352,43456)\n(858,9564,454,76467)\n(17183,4482,3558,345)\n(343477,344,38955,669)\n(890434,347845,555,885769)\n(5664,334,767,34447)\n(45,4574,455647,44477)\n(1234,12451,32352,43456)\n(858,9564,454,76467)\n(17183,4482,3558,345)\n(343477,344,38955,669)\n(890434,347845,555,885769)\n(5664,334,767,34447)\n(45,4574,455647,44477)\n(1234,12451,32352,43456)\n(858,9564,454,76467)\n(17183,4482,3558,345)\n(343477,344,38955,669)\n(890434,347845,555,885769)\n(5664,334,767,34447)\n(45,4574,455647,44477)\n(1234,12451,32352,43456)\n(858,9564,454,76467)\n(17183,4482,3558,345)\n(343477,344,38955,669)\n(890434,347845,555,885769)\n(5664,334,767,34447)\n(45,4574,455647,44477)\n(1234,12451,32352,43456)\n(858,9564,454,76467)\n(17183,4482,3558,345)\n(343477,344,38955,669)\n(890434,347845,555,885769)\n(5664,334,767,34447)\n(45,4574,455647,44477)\n(1234,12451,32352,43456)\n(858,9564,454,76467)\n(17183,4482,3558,345)\n(343477,344,38955,669)\n(890434,347845,555,885769)\n(5664,334,767,34447)\n(45,4574,455647,44477)";
    var someTextArray = someText.split('\n');
};
</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
Test each line with a normal RegExp
var normal = /\(\d+,\d+,\d+,\d+\)/;
for (i in someTextArray) {
   normal.exec(someTextArray[i]);
}
pending…
Test each line with a compiled RegExp
var compiled = new RegExp().compile('\(\d+,\d+,\d+,\d+\)');
for (i in someTextArray) {
   compiled.exec(someTextArray[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