forked from mapbox/supercluster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbench.js
More file actions
36 lines (31 loc) · 834 Bytes
/
bench.js
File metadata and controls
36 lines (31 loc) · 834 Bytes
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
import Supercluster from "./index.js";
import v8 from "v8";
const points = [];
for (let i = 0; i < 1000000; i++) {
points.push({
type: "Feature",
properties: {
index: i,
},
geometry: {
type: "Point",
coordinates: [-180 + 360 * Math.random(), -80 + 160 * Math.random()],
},
});
}
global.gc();
const size = v8.getHeapStatistics().used_heap_size;
const index = new Supercluster({
log: true,
maxZoom: 6,
// map: props => ({sum: props.index}),
// reduce: (accumulated, props) => { accumulated.sum += props.sum; }
getId: (point) => point.properties.index,
}).load(points);
global.gc();
console.log(
`memory used: ${Math.round((v8.getHeapStatistics().used_heap_size - size) / 1024)} KB`,
);
index
.getClusters([-180, -90, 180, 90], 0)
.map((f) => JSON.stringify(f.properties));