Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Chrome 105
Mac OS X 10.15.7
Desktop
2 years ago
Test name Executions per second
With new DataView 42588.5 Ops/sec
With new UInt16Array 50093.0 Ops/sec
With constructed DataView 102511.1 Ops/sec
With constructed UInt16Array 102108.5 Ops/sec
Script Preparation code:
x
 
var size = 0xFF - 1;
var buffer = new ArrayBuffer(size);
var dataview = new DataView(buffer);
var uint16array = new Uint16Array(buffer);
Tests:
  • With new DataView

     
    for (let i = 0; i < size/2; i++) {
      new DataView(buffer, 2*i).getUint16(0)
    }
  • With new UInt16Array

     
    for (let i = 0; i< size/2; i++) {
      new Uint16Array(buffer, 2*i)[0]
    }
  • With constructed DataView

     
    for (let i = 0; i< size/2; i++) {
      dataview.getUint16(2*i)
    }
  • With constructed UInt16Array

     
    for (let i = 0; i< size/2 ; i++) {
      uint16array[i]
    }