Run details:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Chrome 131
Windows
Desktop
23 days ago
Test name Executions per second
DataView 59446236.0 Ops/sec
Uint8Array by byte 61531012.0 Ops/sec
Uint8Array with set 824513.2 Ops/sec
with Float64Array 804934.2 Ops/sec
Script Preparation code:
x
 
var size = 0xFFFF;
var buf = new ArrayBuffer(size);
var view = new DataView(buf);
var byte = new Uint8Array(buf);
var data = new Uint8Array(size);
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);
  • with Float64Array

     
    (new Float64Array(buf, 0, size/8))
          .set(new Float64Array(data.buffer, 0, size/8));