.replace() vs. .split().join() (v5)

Revision 5 of this benchmark created by rmaksim on


Setup

var mystring1 = 'okay this is a string';
  var mystring2 = 'okay.this.is.a.string';

Test runner

Ready to run.

Testing in
TestOps/sec
.replace(/ /g,'.')
result1 = mystring1.replace(/ /g,'.');
ready
.split(' ').join('.')
result1 = mystring1.split(' ').join('.');
ready
.replace(/\./g,' ')
result2 = mystring2.replace(/\./g,' ');
ready
.split('.').join(' ')
result2 = mystring2.split('.').join(' ');
ready

Revisions

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