split/join vs regex replace (v3)

Revision 3 of this benchmark created on


Preparation HTML

<script>
  var str = '<charlie alpha foxtrot> beta <gamma> delta <omega iota kappa> lambda mu nu xi omicron theta <eta> zeta',
      replacewith = {
      '<': '&#60',
      '>': '&#62'
      };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
split/join
str.split('<').join('&#60').split('>').join('&#62')
ready
regex replace
str.replace(/<|>/g, function(a) {
  switch (a) {
  case '<':
    return '&#60';
  case '>':
    return '&#62';
  }
});
ready
regex replace 2
str.replace(/<|>/g, function(a) {
  return replacewith[a];
});
ready

Revisions

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