jquery.trim vs string.prototype.trim

Benchmark created by Rick Waldron on


Preparation HTML

<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>

Test runner

Ready to run.

Testing in
TestOps/sec
jquery.trim 1.4.2
trim12("      hello world          ")
ready
String.prototype.trim
stringTrim("      hello world          ")
ready

Revisions

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