endsWith1

JavaScript performance comparison

Test case created by Brent

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    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";
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
endsWith 1
str.endsWith("abcdefg");
pending…
endsWith2
str.endsWith2("abcdefg");
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment