Native trim vs Regex trim vs mixed (v6)

Revision 6 of this benchmark created on


Setup

var regex = /^\s+|\s+$/g;
    var trim = Function.prototype.call.bind(String.prototype.trim);
    var arr = [];
    for (var i = 0; i < 10; i++) arr.push("  str" + i + "  ");

Test runner

Ready to run.

Testing in
TestOps/sec
Native trim
arr.map(Function.prototype.call, String.prototype.trim);
ready
Regex Trim
arr.map(function(s) {
  return s.replace(regex, '');
});
ready
Native trim without Function.call
arr.map(function(s) {
  return s.trim();
});
ready

Revisions

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