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 rgbaToU321(r, g, b, a) {
const dataView = new DataView(new ArrayBuffer(4));
dataView.setUint32(0,
(Math.round(r) << (3 * 4)) |
(Math.round(g) << (2 * 4)) |
(Math.round(b) << (1 * 4)) |
(Math.round(a) << (0 * 4)));
return dataView.getFloat32(0);
}
function rgbaToU322({r, g, b, a}) {
const dataView = new DataView(new ArrayBuffer(4));
dataView.setUint32(0,
(Math.round(r) << (3 * 4)) |
(Math.round(g) << (2 * 4)) |
(Math.round(b) << (1 * 4)) |
(Math.round(a) << (0 * 4)));
return dataView.getFloat32(0);
}
const sharedArrayBuffer = new ArrayBuffer(4);
const sharedDataView = new DataView(sharedArrayBuffer);
function rgbaToU323(r, g, b, a) {
sharedDataView.setUint32(0,
(Math.round(r) << (3 * 4)) |
(Math.round(g) << (2 * 4)) |
(Math.round(b) << (1 * 4)) |
(Math.round(a) << (0 * 4)));
return sharedDataView.getFloat32(0);
}
function rgbaToU324({r, g, b, a}) {
sharedDataView.setUint32(0,
(Math.round(r) << (3 * 4)) |
(Math.round(g) << (2 * 4)) |
(Math.round(b) << (1 * 4)) |
(Math.round(a) << (0 * 4)));
return sharedDataView.getFloat32(0);
}
const values = [];
for (let i = 0; i < 100000; ++i) {
values.push(i % 256);
}
Ready to run.
Test | Ops/sec | |
---|---|---|
rgbaToU321 |
| ready |
rgbaToU322 |
| ready |
rgbaToU323 |
| ready |
rgbaToU324 |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.