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

Revision 41 of this benchmark created by shilman on


Setup

var mystring = 'okay.this.is.a.string';
  var dynamicRegex = new RegExp(".","");
  var staticRegex = /\./;

Test runner

Ready to run.

Testing in
TestOps/sec
.replace(/\./,' ')
result = mystring.replace(/\./,' ');
ready
.replace(new RegExp(".","")," ")
result = mystring.replace(new RegExp(".","")," ");
ready
.split('.').join(' ')
result = mystring.split('.').join(' ');
ready
Stored Dynamic Regex
result = mystring.replace(dynamicRegex," ");
ready
Stored static Regex
result = mystring.replace(staticRegex," ");
ready
String replace
result = mystring.replace('.',' ');
ready

Revisions

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