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
var $clz32 = Math.clz32;
var $imul = Math.imul;
function v8MathClz32BeforeIntrinsified(x) {
if (x == 0) return 32;
var result = 0;
if ((x & 0xFFFF0000) === 0) { x <<= 16; result += 16; };
if ((x & 0xFF000000) === 0) { x <<= 8; result += 8; };
if ((x & 0xF0000000) === 0) { x <<= 4; result += 4; };
if ((x & 0xC0000000) === 0) { x <<= 2; result += 2; };
if ((x & 0x80000000) === 0) { x <<= 1; result += 1; };
return result;
}
function hackersDelight(x) {
if (x == 0) return 32;
var result = 1;
if ((x & 0xFFFF0000) === 0) { x <<= 16; result += 16; };
if ((x & 0xFF000000) === 0) { x <<= 8; result += 8; };
if ((x & 0xF0000000) === 0) { x <<= 4; result += 4; };
if ((x & 0xC0000000) === 0) { x <<= 2; result += 2; };
return result + (x >> 31);
}
/* From http://aggregate.org/MAGIC/#Leading%20Zero%20Count
* and http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
*/
function bitCountBasedClz32(x) {
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
var t1 = x - ((x >> 1) & 0x55555555);
var t2 = (t1 & 0x33333333) + ((t1 >> 2) & 0x33333333);
return 32 - ($imul((t2 + (t2 >> 4) & 0xF0F0F0F), 0x1010101) >> 24);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Built-in Math.clz32 |
| ready |
V8's implementation before it was an intrinsic |
| ready |
V8 version improved with Hacker's Delight tricks |
| ready |
bitCount-based implementation |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.