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
<p>
DataView offers a standard and easy to use API to read float and integer values of various sizes from a binary buffer at arbitrary byte offsets.
Unfortunately, Firefox's DataView implementation seems to be two orders of magnitudes slower than that of Chrome. Reading 3D models from binary files or processing/transforming 3D data in binary buffers frequently requires the use of DataView. A widely used hack is to use a 4 byte Uint8Array buffer instead, copy the relevant 4 bytes from the source buffer into it, and then interpret this Uint8Array as a Float32Array to retrieve the value. While this is faster than DataView in Firefox, it is also considerably sloer than DataView in chrome. It is also a rather unfortunate and ugly hack.
</p>
function createTestData(size){
let buffer = new ArrayBuffer(4 * size);
let f32 = new Float32Array(buffer);
for(let i = 0; i < size; i++){
f32[i] = Math.random();
}
return buffer;
}
let n = 1_000_000;
let buffer = createTestData(n);
Ready to run.
Test | Ops/sec | |
---|---|---|
using DataView |
| ready |
using u8 array hack |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.