-
Notifications
You must be signed in to change notification settings - Fork 87
/
bench.js
36 lines (30 loc) · 912 Bytes
/
bench.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
36
import Pbf from 'pbf';
import {VectorTile} from './index.js';
import Benchmark from 'benchmark';
import fs from 'fs';
const suite = new Benchmark.Suite();
const data = fs.readFileSync(new URL('test/fixtures/14-8801-5371.vector.pbf', import.meta.url));
readTile(); // output any errors before running the suite
readTile(true);
suite
.add('read tile with geometries', () => {
readTile(true);
})
.add('read tile without geometries', () => {
readTile();
})
.on('cycle', (event) => {
console.log(String(event.target));
})
.run();
function readTile(loadGeom) {
const buf = new Pbf(data),
vt = new VectorTile(buf);
for (const id in vt.layers) {
const layer = vt.layers[id];
for (let i = 0; i < layer.length; i++) {
const feature = layer.feature(i);
if (loadGeom) feature.loadGeometry();
}
}
}