Creating a regex in and outside a loop (v3)

Revision 3 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/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/);
}
ready
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);
}
ready
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/);
}
ready
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);
}
ready
In a loop (single use)
var txt = 'mary is at home';
for(var i = 0; i < 100; i++) {
  txt.match(/mary/);
}
ready
Outside a loop (single use)
var txt = 'mary is at home';
var regex = /mary/;
for(var i = 0; i < 100; i++) {
  txt.match(regex);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Shane O'Sullivan on
  • Revision 3: published on