-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench2.cjs
More file actions
59 lines (50 loc) · 1.82 KB
/
bench2.cjs
File metadata and controls
59 lines (50 loc) · 1.82 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const { performance } = require('perf_hooks');
const numPoints = 200000;
const activeSensorData = [];
for (let i = 0; i < numPoints; i++) {
activeSensorData.push({ x: Math.random() * 100, y: Math.random() * 100, z: Math.random() * 100, val: Math.random(), h: 0 });
}
const instanceMatrixArray = new Float32Array(numPoints * 16);
instanceMatrixArray.fill(0);
// setup
for (let i = 0; i < numPoints; i += 1) {
const point = activeSensorData[i];
const mOff = i * 16;
instanceMatrixArray[mOff + 0] = 1;
instanceMatrixArray[mOff + 5] = 1;
instanceMatrixArray[mOff + 10] = 1;
instanceMatrixArray[mOff + 15] = 1;
instanceMatrixArray[mOff + 12] = point.x;
instanceMatrixArray[mOff + 13] = point.y;
instanceMatrixArray[mOff + 14] = point.z;
}
const worldSize = 2.5;
function oldUpdate() {
instanceMatrixArray.fill(0);
for (let i = 0; i < activeSensorData.length; i += 1) {
const point = activeSensorData[i];
const mOff = i * 16;
instanceMatrixArray[mOff + 0] = worldSize;
instanceMatrixArray[mOff + 5] = worldSize;
instanceMatrixArray[mOff + 10] = 1;
instanceMatrixArray[mOff + 15] = 1;
instanceMatrixArray[mOff + 12] = point.x;
instanceMatrixArray[mOff + 13] = point.y;
instanceMatrixArray[mOff + 14] = point.z;
}
}
function newUpdate() {
const len = activeSensorData.length;
for (let i = 0; i < len; i += 1) {
const mOff = i * 16;
instanceMatrixArray[mOff + 0] = worldSize;
instanceMatrixArray[mOff + 5] = worldSize;
}
}
for (let i = 0; i < 50; i++) { oldUpdate(); newUpdate(); }
let start = performance.now();
for (let i = 0; i < 100; i++) oldUpdate();
console.log('Old Update: ' + (performance.now() - start).toFixed(2) + ' ms');
start = performance.now();
for (let i = 0; i < 100; i++) newUpdate();
console.log('New Update: ' + (performance.now() - start).toFixed(2) + ' ms');