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
function lead(m) {
var c, i;
c = 1 << 31;
for (i = 0; i < 32; i += 1) {
if ((c & m) !== 0) return i;
c >>>= 1;
}
return 32;
}
function lead2(input) {
var output = 0,
curbyte = 0;
while(1) { // emulate goto in JS using the break statement :D
curbyte = input >>> 24;
if (curbyte) break;
output += 8;
curbyte = input >>> 16;
if (curbyte & 0xff) break;
output += 8;
curbyte = input >> 8;
if (curbyte & 0xff) break;
output += 8;
curbyte = input;
if (curbyte & 0xff) break;
output += 8;
return output;
}
if (!(curbyte & 0xf0))
output += 4;
else
curbyte >>>= 4;
if (curbyte & 0x8)
return output;
if (curbyte & 0x4)
return output + 1;
if (curbyte & 0x2)
return output + 2;
if (curbyte & 0x1)
return output + 3;
/* shouldn't get here: */
return output + 4;
}
function lead3(x) {
return 32 - (x).toString(2).length;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
lead |
| ready |
lead2 |
| ready |
lead3 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.