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(true) { // 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;
}
function clz(x) {
if (x < 0) {
return 0
} else if (x == 0) {
return 32
} else {
return 31 - ((Math.log(x) / Math.LN2) >> 0)
}
}
function clz2(x) {
if (x < 1) {
if (x == 0) {
return 32
} else {
return 0
}
} else {
return 32 - ((Math.log(x) / Math.LN2) >> 0)
}
}
function clz3(n) {
if (n & 0xFFFF0000) {
if (n & 0xFF000000) {
if (n & 0x0F0000000) {
if (n & 0x0C0000000) {
return (n & 0x080000000) ? 32 : 31
} else {
return (n & 0x020000000) ? 30 : 29
}
} else {
if (n & 0x00C000000) {
return (n & 0x008000000) ? 28 : 27
} else {
return (n & 0x002000000) ? 26 : 25
}
}
} else {
if (n & 0x000F00000) {
if (n & 0x000C00000) {
return (n & 0x000800000) ? 24 : 23
} else {
return (n & 0x000200000) ? 22 : 21
}
} else {
if (n & 0x0000C0000) {
return (n & 0x000080000) ? 20 : 19
} else {
return (n & 0x000020000) ? 18 : 17
}
}
}
} else {
if (n & 0x00000FF00) {
if (n & 0x00000F000) {
if (n & 0x00000C000) {
return (n & 0x000008000) ? 16 : 15
} else {
return (n & 0x000002000) ? 14 : 13
}
} else {
if (n & 0x000000C00) {
return (n & 0x000000800) ? 12 : 11
} else {
return (n & 0x000000200) ? 10 : 9
}
}
} else {
if (n & 0x0000000F0) {
if (n & 0x0000000C0) {
return (n & 0x000000080) ? 8 : 7
} else {
return (n & 0x000000020) ? 6 : 5
}
} else {
if (n & 0x00000000C) {
return (n & 0x000000008) ? 4 : 3
} else {
return (n & 0x000000002) ? 2 : (n ? 1 : 0)
}
}
}
}
}
var LZ = [8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
var Buffer = new ArrayBuffer(8)
var I = new Int32Array(Buffer)
var B = new Uint8Array(Buffer)
function lookup(x) {
I[0] = x
if (x < 0) {
return 32
}
for (var i = 3; i >= 0; i--) { /* Assuming LE */
var v = LZ[B[i]]
if (v != 8) {
return (3 - i) * 8 - v
}
}
return 32
}
var F = new Float64Array(Buffer)
var I = new Uint32Array(Buffer)
function fpu(x) { /* Assume LE */
F[0] = x | 1
return 1054 - ((I[1] >> 20))
}
var pos = [0, 1, 28, 2, 29, 14, 24, 3,
30, 22, 20, 15, 25, 17, 4, 8,
31, 27, 13, 23, 21, 19, 16, 7,
26, 12, 18, 6, 11, 5, 10, 9]
function lookup2(v) {
v |= v >> 1
v |= v >> 2
v |= v >> 4
v |= v >> 8
v |= v >> 16
v = (v >> 1) + 1
return pos[(v * 0x077CB531) / 134217728]
}
function lookup3(n) {
if(n<0) {
return 0;
} else {
var pLUT = LZ, /* local reference to global */
n1 = n >>> 24,
n2,n3;
if(n1) {
return pLUT[n1];
} else {
n2 = n >>> 16;
if(n2) {
return 8 + pLUT[n2];
} else {
n3 = n >>> 8;
if(n3) {
return 16 + pLUT[n3];
} else {
return 24 + pLUT[n & 0xff];
}
}
}
}
}
function get_clzTable16() {
function clz(n)
{
if(n===0) {return 8;}
if(n & 0x80) {return 0;}
if(n & 0x40) {return 1;}
if(n & 0x20) {return 2;}
if(n & 0x10) {return 3;}
if(n & 0x08) {return 4;}
if(n & 0x04) {return 5;}
if(n & 0x02) {return 6;}
if(n & 0x01) {return 7;}
}
var p = [],n;
for(i=0;i<65536;i++)
{
n = i>>>8;
p[i] = n ? clz(n) : 8+clz(i);
}
return p;
}
var LZ16 = get_clzTable16();
function lookup4(n) {
if(n<0) {
return 0;
} else {
var pLUT = LZ16, /* local reference to global */
n1 = n >>> 16;
if(n1) {
return pLUT[n1];
} else {
return 16 + pLUT[n && 0xffff];
}
}
}
function cmp(n) {
var lz = 0;
if (n === 0) return 32;
if (n < 0x10000) {
lz += 16;
} else {
n >>>= 16;
}
if (n < 0x100) {
lz += 8;
} else {
n >>>= 8;
}
if (n < 0x10) {
lz += 4;
} else {
n >>>= 4
}
if (n < 0x4) {
lz += 2;
} else {
n >>>= 2;
}
if (n < 0x2) {
lz += 1;
}
return lz;
}
function cmp2(n) {
var lz = 0;
if ((n & 0xffff0000) === 0) {
lz += 16;
n <<= 16;
}
if ((n & 0xff000000) === 0) {
lz += 8;
n <<= 8;
}
return lz + LZ[n >>> 24];
}
Ready to run.
Test | Ops/sec | |
---|---|---|
lead |
| ready |
lead2 |
| ready |
lead3 |
| ready |
clz |
| ready |
clz2 |
| ready |
lookup |
| ready |
fpu |
| ready |
lookup2 |
| ready |
clz3 |
| ready |
lookup3 |
| ready |
lookup4 |
| ready |
cmp |
| ready |
cmp2 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.