split/join vs replace (v20)

Revision 20 of this benchmark created by TJ on


Description

Forcibly de-tuned the benchmark to make Chrome spit out a marginally representative result.

Setup

var string = 'coucou/comment/ca/va/bien/le/monde';
    var re = /\//g;

Test runner

Ready to run.

Testing in
TestOps/sec
split/join
string.split(re).join('.')
ready
replace
string.replace(re, '.');
ready
split/join string
string.split('/').join('.')
ready
A la mano
var result = '';
for (var i = 0, length = string.length; i < length; i++) {
  var char = string[i];
  if (char == '/') {
    result += '.';
  } else {
    result += char;
  }
}
ready

Revisions

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