jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
Test the performance of the simplest hash function ever
// Build a lot of average length string to test on
var strs=[];
var strbuff = 'a';
for (var i = 0; i < 1000; i++) {
var lc = strbuff.charAt(strbuff.length - 1);
if (lc == 9) {
strbuff += 'a';
} else if (lc == 'z') {
strbuff = strbuff.substr(0,strbuff.length -1);
strbuff += 'A';
} else if (lc == 'Z') {
strbuff = strbuff.substr(0,strbuff.length -1);
strbuff += '0';
} else {
strbuff = strbuff.substr(0,strbuff.length -1);
strbuff += String.fromCharCode(lc.charCodeAt(0)+1);
}
strs.push(strbuff);
}
function DJBHash(str) {
var hash = 5381;
for(var i = 0; i < str.length; i++) {
hash = ((hash << 5) + hash) + str.charCodeAt(i);
}
return hash;
}
var cache = {};
function DJBCached(str) {
if (!cache[str]) cache[str] = DJBHash(str);
return cache[str];
}
var fnv_prime = 0x811C9DC5;
function MathHash(grx,gry) {
var hash = 0;
hash += grx;
hash *= fnv_prime;
hash = Math.floor(hash % 0xFFFF);
hash /= gry;
hash *= fnv_prime;
return hash;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
DJB on randoms |
| ready |
DJB on average |
| ready |
DJB on randoms cached |
| ready |
DJB on average cached |
| ready |
Math hash on randoms |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.