String Replace All

Benchmark created by LS on


Setup

data = "ab,cd,ef,gh,ij,kl,mn,op,qr,st,uv,wx,yz,";

Test runner

Ready to run.

Testing in
TestOps/sec
String.replace()
data.replace(/,/g, ';')
ready
String.split().join()
data.split(',').join(';')
ready
Loop Words
var out = [], i = 0;
for (var m; ~(m = data.indexOf(',', i)); i = m + 1) {
  out.push(data.substring(i, m));
}
out.push(data.substring(i));
out.join(';');
ready
Loop Chars
var out = [];
for (var i = 0, ic = data.length; i < ic; i++) {
  var c = data.charAt(i);
  if (c == ',')
    c = ';';
  out.push(c);
}
out.join('');
ready
String.replace() 2
data.replace(/[,:]/g, ';')
ready

Revisions

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