dataview vs typed array views (v4)

Revision 4 of this benchmark created on


Setup

var source = new Uint8Array(4);
  
  var uint32 = new Uint32Array(source.buffer);
  
  function readUInt32_1(littleEndian) {
    source[0] = 0x32;
    source[1] = 0x65;
    source[2] = 0x42;
    source[3] = 0x56;
    return uint32[0];
  }
  
  var view = new DataView(source.buffer);
  
  function readUInt32_2(littleEndian) {
    return view.getUint32(0, littleEndian);
  }
  
  function readUInt32_3(littleEndian) {
    var a0 = source[0],
        a1 = source[1],
        a2 = source[2],
        a3 = source[3];
    
    if (littleEndian)
      return ((a3 << 24) >>> 0) + (a2 << 16) + (a1 << 8) + (a0);
    else
      return ((a0 << 24) >>> 0) + (a1 << 16) + (a2 << 8) + (a3);
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Typed Arrays
readUInt32_1();
ready
DataView
readUInt32_2();
ready
Bit twiddling
readUInt32_3();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.