DataView vs. TypedArrayViews

JavaScript performance comparison

Test case created by Niklas Werner

Preparation code

// ----------------------------------------------------------------
// from
var littleEndian = (function() {
  var buffer = new ArrayBuffer(2);
  new DataView(buffer).setInt16(0, 256, true);
  return new Int16Array(buffer)[0] === 256;
// ----------------------------------------------------------------

var byteBuffer = new ArrayBuffer(1);
var byteArray = new Uint8Array(byteBuffer);
var byteView = new DataView(byteBuffer);

var floatBuffer = new ArrayBuffer(4);
var floatArray = new Float32Array(floatBuffer);
var floatView = new DataView(floatBuffer);

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
TypedArrayView - byte
byteArray[0] = 1;
var b = byteArray[0];
DataView - byte
byteView.setUint8(0, 1);
var b = byteView.getUint8(0);
TypedArrayView - float
floatArray[0] = 1;
var f = floatArray[0];
DataView - float
floatView.setFloat32(0, 1, littleEndian);
var f = floatView.getFloat32(0, littleEndian);

Compare results of other browsers


You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:


Comment form temporarily disabled.

Add a comment