String global replace comparison (v26)

Revision 26 of this benchmark created on


Setup

var mystring = 'okay.this.is.a.string.that.is.dot.separated';
  var constructedStatic = new RegExp("\\.","g");
  var shorthandStatic = /\./g;
  
  String.prototype.loopReplace = function(replacee,replacer){
    var result = this;
    while(!!~(result = result.replace('.',' ')).indexOf('.')){}
    return result;
  }

Test runner

Ready to run.

Testing in
TestOps/sec
shorthand, static
result = mystring.replace(shorthandStatic," ");
ready
constructed, static
result = mystring.replace(constructedStatic," ");
ready
constructed on the spot
result = mystring.replace(new RegExp("\\.","g")," ");
ready
shorthand on the spot
result = mystring.replace(/\./g,' ');
ready
split-join
result = mystring.split('.').join(' ');
ready
String replace loop
result = mystring.loopReplace('.',' ');
ready

Revisions

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