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
Changed length checks to use === instead of == and added bitwise and number versions using |= for the 32-bit Integer conversion.
function bitwise(str){
var hash = 0, len = str.length
if (len === 0) return hash;
for (var i = 0; i < len; i++) {
char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
}
return hash;
}
function numbers(str) {
var hash = 0, len = str.length
if (len === 0) return hash;
for (var i = 0; i < len; i++) {
hash = hash * 31 + str.charCodeAt(i);
}
return hash;
}
function bitwiseconv(str){
var hash = 0, len = str.length
if (len === 0) return hash;
for (var i = 0; i < len; i++) {
hash = ((hash<<5)-hash)+str.charCodeAt(i);
hash &= hash; // Convert to 32bit integer
}
return hash;
}
function bitwiseconv2(str){
var hash = 0, len = str.length
if (len === 0) return hash;
for (var i = 0; i < len; i++) {
hash = ((hash<<5)-hash)+str.charCodeAt(i);
hash |= 0; // Convert to 32bit integer
}
return hash;
}
function numbersconv(str) {
var hash = 0, len = str.length
if (len === 0) return hash;
for (var i = 0; i < len; i++) {
hash = hash * 31 + str.charCodeAt(i);
hash &= hash;
}
return hash;
}
function numbersconv2(str) {
var hash = 0, len = str.length
if (len === 0) return hash;
for (var i = 0; i < len; i++) {
hash = hash * 31 + str.charCodeAt(i);
hash |= 0;
}
return hash;
}
function bitwiseReduce(str){
var length = str.length,
a = 0,
i = 0;
for (; i < length; i++) {
a = ((a << 5) - a) + str.charCodeAt(i);
a = a & a;
}
return a;
}
function djbhash (key) {
var hash = 5381,
keyLength = key.length,
i = 0;
for (; keyLength >= 8; keyLength -= 8) {
hash = ((hash << 5) + hash) + key.charCodeAt(i++);
hash = ((hash << 5) + hash) + key.charCodeAt(i++);
hash = ((hash << 5) + hash) + key.charCodeAt(i++);
hash = ((hash << 5) + hash) + key.charCodeAt(i++);
hash = ((hash << 5) + hash) + key.charCodeAt(i++);
hash = ((hash << 5) + hash) + key.charCodeAt(i++);
hash = ((hash << 5) + hash) + key.charCodeAt(i++);
hash = ((hash << 5) + hash) + key.charCodeAt(i++);
}
switch (keyLength) {
case 7: hash = ((hash << 5) + hash) + key.charCodeAt(i++);
case 6: hash = ((hash << 5) + hash) + key.charCodeAt(i++);
case 5: hash = ((hash << 5) + hash) + key.charCodeAt(i++);
case 4: hash = ((hash << 5) + hash) + key.charCodeAt(i++);
case 3: hash = ((hash << 5) + hash) + key.charCodeAt(i++);
case 2: hash = ((hash << 5) + hash) + key.charCodeAt(i++);
case 1:
hash = ((hash << 5) + hash) + key.charCodeAt(i++);
break;
case 0:
break;
}
return hash;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Bitwise based function (No integer conversion) |
| ready |
Number based function (No integer conversion) |
| ready |
Bitwise based function |
| ready |
Number based function |
| ready |
Reduce + bitwise |
| ready |
DJB |
| ready |
Bitwise based function (Integer convert with |=) |
| ready |
Number based function (Integer convert with |=) |
| ready |
JSON stringify |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.