dataview vs typed array views (v29)

Revision 29 of this benchmark created on


Setup

var bytes = 2**24;
var ab = new ArrayBuffer(bytes);
var f32 = new Float32Array(ab)
var source = new Uint8Array(ab);
for (var i = 0; i < f32.length; i++) {
	f32[i] = Math.random() * 1000 + Math.random() * 1000000;
}
var view = new DataView(ab);
var viewGetUint8 = view.getUint8.bind(view);
var viewSetUint8 = view.setUint8.bind(view);
var acc = 0;

Teardown

for (var i = 0; i < f32.length; i++) {
	f32[i] = Math.random() * 1000 + Math.random() * 1000000;
}

Test runner

Ready to run.

Testing in
TestOps/sec
DataView get
acc = 0;
for (var i = 0; i < bytes; i++) {
	acc += viewGetUint8(i);
}
ready
Typed Array get
acc = 0;
for (var i = 0; i < bytes; i++) {
	acc += source[i];
}
ready
DataView set
for (var i = 0; i < bytes; i++) {
	viewSetUint8(i, i % 256);
}
ready
Typed Array set
for (var i = 0; i < bytes; i++) {
	source[i] = i % 256;
}
ready

Revisions

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