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
const generateHashCode = function (str) {
let hash = 0;
if (str.length === 0) return hash;
for (let i = 0; i < str.length; i++) {
const chr = str.charCodeAt(i);
hash = (hash << 5) - hash + chr;
hash |= 0;
}
return hash;
};
const isSessionInSample = function (sessionId, sampleRate) {
const hashNumber = generateHashCode(sessionId.toString());
const absHash = Math.abs(hashNumber);
const absHashMultiply = absHash * 31;
const mod = absHashMultiply % 100;
return mod / 100 < sampleRate;
};
Ready to run.
Test | Ops/sec | |
---|---|---|
Before |
| ready |
After |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.