为什么TypedArrays不像通常的数组那么快?我想为CLZ使用precalc值(计算前导零函数).而且我不希望他们像往常一样解释对象?
http://jsperf.com/array-access-speed-2/2
准备代码:
Benchmark.prototype.setup = function() {
var buffer = new ArrayBuffer(0x10000);
var Uint32 = new Uint32Array(buffer);
var arr = [];
for(var i = 0; i < 0x10000; ++i) {
Uint32[i] = (Math.random() * 0x100000000) | 0;
arr[i] = Uint32[i];
}
var sum = 0;
};
Run Code Online (Sandbox Code Playgroud)
测试1:
sum = arr[(Math.random() * 0x10000) | 0];
Run Code Online (Sandbox Code Playgroud)
测试2:
sum = Uint32[(Math.random() * 0x10000) | 0];
Run Code Online (Sandbox Code Playgroud)

PS可能是我的性能测试无效随时纠正我.