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
Ways to find the most significant bit inside a bigint
.
function loop(a) {
const one = BigInt(1);
let position = -1;
while (a > 0) {
a = (a >> one);
position++;
}
return position;
}
function clz1(a) {
let offset = 0;
for (; (a & ~BigInt(0xFFFFFFFF)) > 0; a >>= BigInt(32)) {
offset += 32;
}
return offset + (31 - Math.clz32(Number(a)));
}
function clz2(a) {
const MASK = ~BigInt(0xFFFFFFFF);
const SHIFT = BigInt(32);
let offset = 0;
for (; (a & MASK) > 0; a >>= SHIFT) {
offset += 32;
}
return offset + (31 - Math.clz32(Number(a)));
}
function clz3(a) {
const MASK = ~0xFFFFFFFFn;
let offset = 0;
for (; (a & MASK) > 0; a >>= 32n) {
offset += 32;
}
return offset + (31 - Math.clz32(Number(a)));
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Loop |
| ready |
CLZ |
| ready |
CLZ w/ Const |
| ready |
CLZ w/ Const & Literal |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.