Replace All vs Split/Join

JavaScript performance comparison

Revision 64 of this test case created by Roman Petrov

Preparation code

Benchmark.prototype.setup = function() {
  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)
  var replaceIndexOf = function(value, search, replacement) {
      var result = value;
      if (result) {
          while (result.indexOf(search) >= 0) {
              result = result.replace(search, replacement);
      return result;


Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Replace indexOf
str = replaceIndexOf(str, "abc", "")


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