Javascript compiled regex

JavaScript performance comparison

Revision 13 of this test case created

Info

Just what exactly does .compile() do?

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var normal = /\(\d+,\d+,\d+,\d+\)/;
    var object = new RegExp('\\(\\d+,\\d+,\\d+,\\d+\\)');
    var compiled1 = new RegExp('\\(\\d+,\\d+,\\d+,\\d+\\)');
    compiled1.compile();
    var compiled2 = new RegExp()
    compiled2.compile('\\(\\d+,\\d+,\\d+,\\d+\\)');
    var globalNormal = /\(\d+,\d+,\d+,\d+\)/g;
   
    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
normal RegExp
for (c = 0; c < 1000000; c++) {
  for (i in someTextArray) {
    normal.exec(someTextArray[i]);
  }
}
pending…
object RegExp
for (c = 0; c < 1000000; c++) {
  for (i in someTextArray) {
    object.exec(someTextArray[i]);
  }
}
pending…
compiled1 RegExp
for (c = 0; c < 1000000; c++) {
  for (i in someTextArray) {
    compiled1.exec(someTextArray[i]);
  }
}
pending…
compiled2 RegExp
for (c = 0; c < 1000000; c++) {
  for (i in someTextArray) {
    compiled2.exec(someTextArray[i]);
  }
}
pending…
global normal RegExp
for (c = 0; c < 1000000; c++) {
  globalNormal.exec(''); // to reset the regex
  while (match = globalNormal.exec(someText)) {
    var a = match;
  }
}
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