jquery.trim vs string.prototype.trim (v13)

Revision 13 of this benchmark created by Daniel Ricci on


Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
  function trim12(str) {
   var str = str.replace(/^\s\s*/, ''),
       ws = /\s/,
       i = str.length;
   while (ws.test(str.charAt(--i)));
   return str.slice(0, i + 1);
  }
  
  var stringTrim = String.prototype.trim;
</script>

Setup

var test = new String("      hello world          ");

Test runner

Ready to run.

Testing in
TestOps/sec
jquery.trim 1.9.1
$.trim(test)
ready
String.prototype.trim
test.trim()
ready

Revisions

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