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
<script>
var log2a = function(x) {
return Math.floor(Math.log(x) / Math.log(2));
};
var log2b = function(x) {
var r = 0;
while (x >>>= 1) r++;
return r;
};
var log2c = function(x) {
var r = 0;
if (x >= 65536) {
x >>>= 16;
r += 16;
}
if (x >= 256) {
x >>>= 8;
r += 8;
}
if (x >= 16) {
x >>>= 4;
r += 4;
}
if (x >= 4) {
x >>>= 2;
r += 2;
}
if (x >= 2) r += 1;
return r;
};
var log2d = function(x) {
var r = 0;
if (x & 0xFFFF0000) {
x >>>= 16;
r |= 16;
}
if (x & 0xFF00) {
x >>>= 8;
r |= 8;
}
if (x & 0xF0) {
x >>>= 4;
r |= 4;
}
if (x & 0xC) {
x >>>= 2;
r |= 2;
}
if (x & 0x2) {
x >>>= 1;
r |= 1;
}
return r;
};
var log2e = function(x) {
var r = (x > 0xFFFF) << 4;
x >>>= r;
var s = (x > 0xFF) << 3;
x >>>= s;
r |= s;
s = (x > 0xF) << 2;
x >>>= s;
r |= s;
s = (x > 0x3) << 1;
x >>>= s;
r |= s;
r |= (x >> 1);
return r;
};
var log2f = function(x) {
var lgt = [-1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7];
var r, t, tt;
if (tt = x >>> 16) r = (t = tt >>> 8) ? 24 + lgt[t] : 16 + lgt[tt];
else r = (t = x >>> 8) ? 8 + lgt[t] : lgt[x];
return r;
};
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
Math.log |
| ready |
Naïve bits counting |
| ready |
Compare and branch |
| ready |
Better compare and branch |
| ready |
Compare without branching |
| ready |
Table lookup |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.