RegEx-templating (v2)

Revision 2 of this benchmark created by Martin Reurings on


Description

A performance test to measure the impact of how regular expressions are used in a templating system.

Preparation HTML

<script>
  var data1 = {
    "test1": "value1",
    "test2": "value2",
    "test3": "value3"
  }
  
  var template1 = "This is {test1} to see how fast different {test2}-replacement techniques perform! ({test3})";
  
  var sRE = /{([^}]+)}/gi;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Dynamic Regular Expressions
var template = template1;
for (var i in data1) {
  template = template.replace(new RegExp('{' + i + '}', 'g'), data1[i]);
}
ready
Static Regular Expression
var o = template1;
var m;
while (m = sRE.exec(o)) {
  o = RegExp.leftContext;
  o += data1[m[1]];
  o += RegExp.rightContext;
  sRE.test("");
}
ready

Revisions

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

  • Revision 1: published by Martin Reurings on
  • Revision 2: published by Martin Reurings on
  • Revision 3: published by Martin Reurings on
  • Revision 4: published on
  • Revision 5: published by Martin Reurings on
  • Revision 6: published on
  • Revision 7: published on
  • Revision 9: published by Martin Reurings on