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
const string = 'C0ffeeFeee';
const fromHexString = (hexString) =>
Uint8Array.from(hexString.match(/.{1,2}/g).map((byte) => parseInt(byte, 16)));
function h2b_efficient(hex) {
const binary = new Uint8Array(hex.length >> 1);
let char;
for (let i = 0; i < hex.length; i++) {
char = hex.charCodeAt(i);
if (char >= 48 && char <= 57) {
char -= 48;
} else if (char >= 65 && char <= 70) {
char -= 55;
} else if (char >= 97 && char <= 102) {
char -= 87;
} else {
continue;
}
if (i & 1) {
binary[i >> 1] <<= 4;
binary[i >> 1] |= char;
} else {
binary[i >> 1] = char;
}
}
return binary;
}
const HEX_STRINGS = "0123456789abcdef";
const MAP_HEX = {
0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6,
7: 7, 8: 8, 9: 9, a: 10, b: 11, c: 12, d: 13,
e: 14, f: 15, A: 10, B: 11, C: 12, D: 13,
E: 14, F: 15
};
function fromHex(hexString) {
const bytes = new Uint8Array(Math.floor((hexString || "").length / 2));
let i;
for (i = 0; i < bytes.length; i++) {
const a = MAP_HEX[hexString[i * 2]];
const b = MAP_HEX[hexString[i * 2 + 1]];
if (a === undefined || b === undefined) {
break;
}
bytes[i] = (a << 4) | b;
}
return i === bytes.length ? bytes : bytes.slice(0, i);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
h2b_efficient |
| ready |
fromHex |
| ready |
fromHexString |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.