Creating a regex in and outside a loop

JavaScript performance comparison

Revision 3 of this test case created by

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
In a loop (multiple uses)
var txt1 = 'mary is at home';
var txt2 = 'john is at home';
for(var i = 0; i < 100; i++) {
  txt1.match(/mary/);
  txt2.match(/mary/);
}
pending…
Outside a loop (multiple uses)
var txt1 = 'mary is at home';
var txt2 = 'john is at home';
var regex = /mary/;
for(var i = 0; i < 100; i++) {
  txt1.match(regex);
  txt2.match(regex);
}
pending…
In a loop (different regexps)
var txt1 = 'mary is at home';
var txt2 = 'john is at home';
for(var i = 0; i < 100; i++) {
  txt1.match(/mary/);
  txt2.match(/john/);
}
pending…
Outside a loop (different regexps)
var txt1 = 'mary is at home';
var txt2 = 'john is at home';
var regex1 = /mary/;
var regex2 = /john/;
for(var i = 0; i < 100; i++) {
  txt1.match(regex1);
  txt2.match(regex2);
}
pending…
In a loop (single use)
var txt = 'mary is at home';
for(var i = 0; i < 100; i++) {
  txt.match(/mary/);
}
pending…
Outside a loop (single use)
var txt = 'mary is at home';
var regex = /mary/;
for(var i = 0; i < 100; i++) {
  txt.match(regex);
}
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.

0 Comments