Replace All vs Split/Join (v10)

Revision 10 of this benchmark created on


Setup

str = "Test abc test test abc test...";
    reg_exp = new RegExp('abc', 'g');
    replaceAll = function(string, omit, place, prevstring) {
      if (prevstring && string === prevstring)
        return string;
      prevstring = string.replace(omit, place);
      return replaceAll(prevstring, omit, place, string)
    }

Test runner

Ready to run.

Testing in
TestOps/sec
split & join
str.split("abc").join("");
ready
replace
str.replace(/abc/g, '');
ready
replaceAll custom function
str = replaceAll(str, "abc", "")
ready
replace with cached regexp
str.replace(reg_exp, '');
ready

Revisions

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