replace() or substr() (v6)

Revision 6 of this benchmark created on


Setup

var str = "a.aa.a.aa.";
    var regEx = /\.$/;

Test runner

Ready to run.

Testing in
TestOps/sec
substr
str = str.substr(0, str.length - 1);
ready
replace
str = str.replace(/\.$/, '');
ready
precompiled replace
str = str.replace(regEx, '');
ready
indexOf() and concat
var i = str.indexOf('.');
if (i >= 0) {
  var s = str;
  str = s.substr(0, i);
  str += s.substr(i + 1);
}
ready

Revisions

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