string regexp replace vs loop indexof replaces (v11)

Revision 11 of this benchmark created on


Setup

r = /\./g;
    
    str = '1.2.3.4.5.6.7.8.9.0';
    
    function regexReplace(){
      str.replace(/\./g, ',');
    }
    
    function stringReplace(){
      while (str.indexOf('.') !== -1) {
        str = str.replace('.', ',');
      }
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Regex replace
str.replace(/\./g, ',');
ready
String replace
while (str.indexOf('.') !== -1) {
  str = str.replace('.', ',');
}
 
ready
Regex replace (function call)
regexReplace();
ready
String replace (function call)
stringReplace();
ready
Split and Join
str = str.split('.').join(',');
ready

Revisions

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