string trim

Benchmark created by ixkungfu 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

Revisions

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