RegExp test vs. Match

JavaScript performance comparison

Test case created by Pointy

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/;
</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
Match
var list = [];
for (var i = 0; i < strings.length; ++i) {
 var b = strings[i].match(regex1),
     b2 = strings[i].match(regex2),
     b3 = strings[i].match(regex3);
 list.push(b || b2 || b3);
}
pending…
Test
var list = [];
for (var i = 0; i < strings.length; ++i) {
 var b = regex1.test(strings[i]),
     b2 = regex2.test(strings[i]),
     b3 = regex3.test(strings[i]);
 list.push(b || b2 || b3);
}
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