endsWith1

Benchmark created by Brent on


Setup

String.prototype.endsWith2 = function(suffix) {
      return this.indexOf(suffix, this.length - suffix.length) !== -1;
  };
  
  String.prototype.endsWith = function (s) {
    return this.length >= s.length && this.substr(this.length - s.length) == s;
  }
  
  var str = "abcdefgabcdefgl;aljsldkjfkljklklaskdlfweijozjcklabcdefgx";

Test runner

Ready to run.

Testing in
TestOps/sec
endsWith 1
str.endsWith("abcdefg");
ready
endsWith2
str.endsWith2("abcdefg");
ready

Revisions

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

  • Revision 1: published by Brent on