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 hextoRgb(hex) {
if (/^#/i.test(hex)) {
hex = hex.replace('#', '');
}
if (hex.length === 3) {
const rHex = hex.substring(0,1);
const gHex = hex.substring(1, 2);
const bHex = hex.substring(2, 3);
hex = `${rHex}${rHex}${gHex}${gHex}${bHex}${bHex}`;
}
const rDec = parseInt(hex.substring(0, 2), 16);
const gDec = parseInt(hex.substring(2, 4), 16);
const bDec = parseInt(hex.substring(4, 6), 16);
return `rgb(${rDec},${gDec},${bDec})`;
}
function hextoRgb2(hex) {
let r = 0x0;
let b = 0x0;
let g = 0x0;
if (hex[0] === '#') {
hex = hex.slice(1);
}
let num = parseInt(hex, 16);
if (num <= 0xFFF) {
b = num & 0xF;
b |= b << 4;
num >>= 4;
g = num & 0xF;
g |= g << 4;
num >>= 4;
r = num;
r |= r << 4;
} else {
b = num & 0xFF;
num >>= 8;
g = num & 0xFF;
num >>= 8;
r = num;
}
return `rgb(${r},${g},${b})`;
}
const hextoRgb3 = hex => {
let r = 0x0
let b = 0x0
let g = 0x0
hex.startsWith('#') && (hex = hex.slice(1))
let num = parseInt(hex, 16)
if (num <= 0xFFF) {
b = num & 0xF
b |= b << 4
num >>= 4
g = num & 0xF
g |= g << 4
num >>= 4
r = num
r |= r << 4
} else {
b = num & 0xFF
num >>= 8
g = num & 0xFF
num >>= 8
r = num
}
return `rgb(${r},${g},${b})`
}
Ready to run.
Test | Ops/sec | |
---|---|---|
Not optimized |
| ready |
Optimized |
| ready |
Optimized 2 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.