.replace() vs. conditional (v48)

Revision 48 of this benchmark created on


Setup

var mystring = 'okay.this.is.a.string';
  var regexp = new RegExp(".", "g");
  var alternator = 1;

Test runner

Ready to run.

Testing in
TestOps/sec
.replace(/\./g,' ')
result = mystring.replace(/\./g, ' ');
ready
if/else block
if(alternator) {
    mystring = 'foo' + alternator;
    alternator = 0;
} else {
    mystring = 'baz' + alternator;
    alternator = 1;
}
ready

Revisions

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