js ArrayBufferView & TypeArray All In One

js ArrayBufferView & TypeArray All In One



// ✅ > 100000
2**64;
18446744073709552000

// ✅ > 100000
2**32;
4294967296

// ❌ 太小了 < 100000
2**16;
65536

// ❌ 太小了 < 100000
2**8;
256

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

Uint8Array

js no for 100 array


const arr = new Uint8Array(100).map((item, i) => i);
 

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array

Uint32Array

js 數組裏面有10萬個數據,取第 1 個元素和第 10 萬個元素的時間相差多少?


const arr = (new Uint32Array(100000)).map((item, i) => i +  1);

function testPerformance(arr, i) {
  let startTime = performance.now();
  console.log(`arr[i], i =`, arr[i], i);
  let endTime = performance.now();
  console.log(`🚀performance time is \`${endTime - startTime}\` ms`);
}

function testTime(arr, i) {
  console.time('array test');
  console.log(`arr[i], i =`, arr[i], i);
  console.timeEnd('array test');
}

testPerformance(arr, 0);
testPerformance(arr, 99999);

console.log('\n');

testTime(arr, 0);
testTime(arr, 99999);

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array

BigUint64Array


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigUint64Array

refs

https://www.cnblogs.com/xgqfrms/p/8982974.html

https://www.cnblogs.com/xgqfrms/p/16714232.html



©xgqfrms 2012-2020

www.cnblogs.com/xgqfrms 發佈文章使用:只允許註冊用戶纔可以訪問!

原創文章,版權所有©️xgqfrms, 禁止轉載 🈲️,侵權必究⚠️!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章