Why are TypedArrays not faster than usual arrays? I want to use precalculate values for CLZ (compute leading zeros function). And I don't want they interpreting as usual objects?
http://jsperf.com/array-access-speed-2/2
Preparation code:
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;
};
Test 1:
sum = arr[(Math.random() * 0x10000) | 0];
Test 2:
sum = Uint32[(Math.random() * 0x10000) | 0];
PS: May be my perf tests are invalid feel free to correct me.