相关疑难解决方法(0)

Javascript TypedArray性能

为什么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可能是我的性能测试无效随时纠正我.

javascript performance typed-arrays

20
推荐指数
2
解决办法
1万
查看次数

标签 统计

javascript ×1

performance ×1

typed-arrays ×1