BrunoLM (v2)

Revision 2 of this benchmark created by BrunoLM on


Description

My tests

Preparation HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/linq.js/2.2.0.2/linq.min.js"></script>

Setup

String.prototype.hashCode = function(){
        var hash = 0, i, char;
        if (this.length == 0) return hash;
        for (i = 0, l = this.length; i < l; i++) {
            char  = this.charCodeAt(i);
            hash  = ((hash<<5)-hash)+char;
            hash |= 0; // Convert to 32bit integer
        }
        return hash;
    };
    
    String.prototype.hashCode2 = function(){
      return this.split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0);              
    }
    
    String.prototype.hashCode3 = function() {
      for(var ret = 0, i = 0, len = this.length; i < len; i++) {
        ret = (31 * ret + this.charCodeAt(i)) << 0;
      }
      return ret;
    };

Test runner

Ready to run.

Testing in
TestOps/sec
1
"123".hashCode();
ready
2
"123".hashCode2();
ready
3
"123".hashCode3();
ready

Revisions

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

  • Revision 2: published by BrunoLM on