-
Notifications
You must be signed in to change notification settings - Fork 40
/
bench.js
48 lines (40 loc) · 1.49 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
'use strict';
var Benchmark = require('benchmark');
var cover = require('./index.js').tiles;
var fs = require('fs');
var building = JSON.parse(fs.readFileSync('./test/fixtures/building.geojson'));
var line = JSON.parse(fs.readFileSync('./test/fixtures/road.geojson'));
var point = JSON.parse(fs.readFileSync('./test/fixtures/point.geojson'));
var russia = JSON.parse(fs.readFileSync('./test/fixtures/russia.geojson'));
var russiaLine = {type: 'LineString', coordinates: russia.coordinates[0]};
var zooms = [6, 8, 10, 12, 18, 20, 25, 28];
var suite = new Benchmark.Suite('tile-cover', {
onError: function (err) {
console.log(err);
}
});
addBench(suite, point, 'point', zooms[0], zooms[0]);
zooms.forEach(function (zoom) {
addBench(suite, line, 'road', zoom, zoom);
});
zooms.forEach(function (zoom) {
addBench(suite, building, 'building', zoom, zoom);
});
zooms.slice(0, 3).forEach(function (zoom) {
addBench(suite, russia, 'russia polygon', zoom, zoom);
});
zooms.slice(0, 3).forEach(function (zoom) {
addBench(suite, russiaLine, 'russia polyline', zoom, zoom);
});
addBench(suite, russia, 'russia polygon multizoom', 0, 9);
suite.on('cycle', function (event) {
console.log(String(event.target));
}).run();
function addBench(suite, geometry, name, min_zoom, max_zoom) {
suite.add('scan ' + name + ' - z' + min_zoom + ' - z' + max_zoom, {
fn: function () {
cover(geometry, {min_zoom: min_zoom, max_zoom: max_zoom});
},
maxTime: 1
});
}