-
Notifications
You must be signed in to change notification settings - Fork 17
/
bench.js
75 lines (62 loc) · 1.79 KB
/
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const fs = require("fs");
const turf = require("@turf/turf");
const shst = require("sharedstreets");
const tripMatch = require("./src/matchers/trip");
const changeMatch = require("./src/matchers/change");
const config = require("./test/fixtures/cli/config.json");
const cover = require("@mapbox/tile-cover");
const z = 19;
const zs = { min_zoom: z, max_zoom: z };
async function bench() {
config.zones.features = config.zones.features.map(zone => {
zone.properties.keys = {};
cover.indexes(zone.geometry, zs).forEach(key => {
zone.properties.keys[key] = 1;
});
return zone;
});
const envelope = turf.bboxPolygon(config.boundary).geometry;
const graphOpts = {
source: "osm/planet-181224",
tileHierarchy: 6
};
var graph = new shst.Graph(envelope, graphOpts);
await graph.buildGraph();
const trips = fs
.readFileSync("./example/data/Spuun/trips.json")
.toString()
.split("\n")
.filter(l => {
return l.length;
})
.map(JSON.parse);
const changes = fs
.readFileSync("./example/data/Spuun/changes.json")
.toString()
.split("\n")
.filter(l => {
return l.length;
})
.map(JSON.parse);
var start = new Date().getTime();
var count = 0;
for (let trip of trips) {
count++;
await tripMatch(trip, config, graph);
}
var stop = new Date().getTime();
console.log("trip match avg: " + ((stop - start) / count).toFixed(4) + "ms");
console.log("measured across " + count + " trips");
count = 0;
start = new Date().getTime();
for (let change of changes) {
count++;
await changeMatch(change, config, graph);
}
stop = new Date().getTime();
console.log(
"change match avg: " + ((stop - start) / count).toFixed(4) + "ms"
);
console.log("measured across " + count + " changes");
}
bench();