.replace() vs. .split().join() vs .replaceAll() (v11)

Revision 11 of this benchmark created on


Setup

var mystring = 'okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.okay.this.is.a.string.',
  re = new RegExp(".","g"),
  re2 = /\./g;

Test runner

Ready to run.

Testing in
TestOps/sec
.replace(/\./g,' ')
result = mystring.replace(/\./g,' ');
ready
.replace(new RegExp(".","g")," ")
result = mystring.replace(new RegExp(".","g")," ");
ready
.split('.').join(' ')
result = mystring.split('.').join(' ');
ready
mystring.replace(re," ");
result = mystring.replace(re," ");
ready
mystring.replace(re2," ");
result = mystring.replace(re2," ");
ready

Revisions

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