ArrayBuffer vs Array vs variable R/W Speed (v6)

Revision 6 of this benchmark created by Getkey on


Description

Speed comparison of ArrayBuffer vs Array vs variables for random access reading and writing.

Test runner

Ready to run.

Testing in
TestOps/sec
ArrayBuffer 32-bit Write
var arr = new Uint32Array(2048);

for (var i = 0, j = arr.length; i < j; ++i) {
  arr[i] = 0xFF;
}
ready
ArrayBuffer 32-bit Read
var arr = new Uint32Array(2048);

for (var i = 0, j = arr.length; i < j; ++i) {
  if (arr[i]) {
    continue;
  }
}
ready
ArrayBuffer 8-bit Write
var arr = new Uint8Array(2048);

for (var i = 0, j = arr.length; i < j; ++i) {
  arr[i] = 0xFF;
}
ready
ArrayBuffer 8-bit Read
var arr = new Uint8Array(2048);

for (var i = 0, j = arr.length; i < j; ++i) {
  if (arr[i]) {
    continue;
  }
}
ready
Array Write
var arr = new Array(2048);

for (var i = 0, j = arr.length; i < j; ++i) {
  arr[i] = 0xFF;
}
ready
Array Read
var arr = new Array(2048);

for (var i = 0, j = arr.length; i < j; ++i) {
  if (arr[i]) {
    continue;
  }
}
ready
ArrayBuffer 16-bit Write
var arr = new Uint16Array(2048);

for (var i = 0, j = arr.length; i < j; ++i) {
  arr[i] = 0xFF;
}
ready
ArrayBuffer 16-bit Read
var arr = new Uint16Array(2048);

for (var i = 0, j = arr.length; i < j; ++i) {
  if (arr[i]) {
    continue;
  }
}
ready
var Write
var variable = 0;

for (var i = 0, j = 2048; i < j; ++i) {
  variable = 0xFF;
}
ready
var Read
var variable = 0;

for (var i = 0, j = 2048; i < j; ++i) {
  if (variable) {
    continue;
  }
}
ready
let Write
let variable = 0;

for (var i = 0, j = 2048; i < j; ++i) {
  variable = 0xFF;
}
ready
let Read
let variable = 0;

for (var i = 0, j = 2048; i < j; ++i) {
  if (variable) {
    continue;
  }
}
ready

Revisions

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