string trim (v2)

Revision 2 of this benchmark created on


Description

text.toString().replace(/^\s+/, "" ).replace(/\s+$/, "" ) VS text.toString().replace(/^\s+|\s+$/g, ""); vs String.prototype.trim.call(text);

Test runner

Ready to run.

Testing in
TestOps/sec
left+right
var t = '            google              ';
t.toString().replace(/^\s+/, "").replace(/\s+$/, "");
ready
all
var t = '            google              ';
t.toString().replace(/^\s+|\s+$/g, "");
ready
left+right no use toString
var t = '            google              ';
t.replace(/^\s+/, "").replace(/\s+$/, "");
ready
all no use toString
var t = '            google              ';
t.replace(/^\s+|\s+$/g, "");
ready
call
var t = '            google              ';
String.prototype.trim.call(t);
ready
plain trim
var t = '            google              ';
t.trim();
ready

Revisions

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