만화로 소개하는 ArrayBuffer 와 SharedArrayBuffer ★ Mozilla 웹 기술 블로그
Diving deep into JavaScript array - evolution & performance
Are JavaScript arrays actually linked lists?
Are node.js arrays actually hashmaps?
var buffer = new ArrayBuffer(12);
var dataView = new DataView(buffer);
var int8View = new Int8Array(buffer);
dataView.setInt32(0, 0x1234abcd);
console.log(dataView.getInt32(0).toString(16));
console.log(dataView.getInt8(0).toString(16));
console.log(int8View[0].toString(16));
var LIMIT = 10000000;
var arr = new Array(LIMIT);
arr.push({ a: 22 });
for (var i = 0; i < LIMIT; i++) {
arr[i] = i;
}
var p;
console.time("Array read time");
for (var i = 0; i < LIMIT; i++) {
//arr[i] = i;
p = arr[i];
}
console.timeEnd("Array read time");
var LIMIT = 10000000;
var buffer = new ArrayBuffer(LIMIT * 4);
var arr = new Int32Array(buffer);
console.time("ArrayBuffer insertion time");
for (var i = 0; i < LIMIT; i++) {
arr[i] = i;
}
console.time("ArrayBuffer read time");
for (var i = 0; i < LIMIT; i++) {
var p = arr[i];
}
console.timeEnd("ArrayBuffer read time");