-
Notifications
You must be signed in to change notification settings - Fork 1
/
object_flat.js
35 lines (30 loc) · 972 Bytes
/
object_flat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function Array3(nx, ny, nz) {
this.data = new Float32Array(nx * ny * nz);
this.shape = [nx,ny,nz];
this.stride = [ny*nz, nz, 1];
this.offset = 0;
}
Array3.prototype.get = function(i, j, k) {
return this.data[this.stride[0] * i + this.stride[1] * j + this.stride[2] * k + this.offset];
};
Array3.prototype.set = function(i,j,k, v) {
this.data[this.stride[0] * i + this.stride[1] * j + this.stride[2] * k + this.offset] = v;
};
function initArray(nx, ny, nz) {
return new Array3(nx, ny, nz);
}
function benchmark(A, B, nx, ny, nz, num_iter) {
for(var count=0; count<num_iter; ++count) {
for(var i=0; i<nx; ++i) {
for(var j=0; j<ny; ++j) {
for(var k=0; k<nz; ++k) {
A.set(i, j, k, A.get(i, j, k) + B.get(i, j, k) + 0.1);
B.set(i, j, k, B.get(i, j, k) - A.get(i, j, k) * 0.5);
}
}
}
}
}
exports.benchmark = benchmark;
exports.initArray = initArray;
exports.prop_name = "object with flat accessor";