Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.56
Chrome 107
Windows
Desktop
2 years ago
Test name Executions per second
DataView 21108392.0 Ops/sec
Uint8Array by byte 21128900.0 Ops/sec
Uint8Array with set 1276160.0 Ops/sec
Script Preparation code:
x
 
var size = 0xFF;
var buf = new ArrayBuffer(size);
var view = new DataView(buf);
var byte = new Uint8Array(buf);
var data = [];
for (let i = 0; i < size; i++) {
    data[i] = 100*Math.random();
}
Tests:
  • DataView

     
    for (let i; i < size; i++) {
        view.setUint8(i, data[i]);
    }
  • Uint8Array by byte

     
    for (let i; i < size; i++) {
        byte[i] = data[i];
    }
  • Uint8Array with set

     
    byte.set(data, 0);