dataview vs typed array views

JavaScript performance comparison

Revision 4 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  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);
  }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Typed Arrays
readUInt32_1();
pending…
DataView
readUInt32_2();
pending…
Bit twiddling
readUInt32_3();
pending…

Compare results of other browsers

Revisions

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

0 Comments