-
Notifications
You must be signed in to change notification settings - Fork 22.9k
/
benchmark.js
64 lines (47 loc) · 1.53 KB
/
benchmark.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
require("../env");
var fs = require("fs");
var formatNumber = d3.format(",.02r"),
projection = d3.geo.stereographic().clipAngle(150),
path = d3.geo.path().projection(projection),
graticule = d3.geo.graticule().step([1, 1]),
circle = d3.geo.circle().angle(30),
n = 10,
o,
then;
o = JSON.parse(fs.readFileSync("./test/data/us-counties.json"));
then = Date.now();
for (var i = 0, k = 0; i < n; i++, k++) {
path(o);
}
console.log("U.S. counties: " + formatNumber((Date.now() - then) / k) + "ms/op.");
o = graticule();
then = Date.now();
for (var i = 0, k = 0; i < n; i++, k++) {
path(o);
}
console.log("Dense graticule: " + formatNumber((Date.now() - then) / k) + "ms/op.");
o = {type: "GeometryCollection", geometries: d3.range(-180, 180, 1).map(function(x) {
return circle.origin([x, 0])();
})};
then = Date.now();
for (var i = 0, k = 0; i < n; i++, k++) {
path(o);
}
console.log("Circle polygons: " + formatNumber((Date.now() - then) / k) + "ms/op.");
o = spiral();
then = Date.now();
for (var i = 0, k = 0; i < n; i++, k++) {
path(o);
}
console.log("Spiral polygons: " + formatNumber((Date.now() - then) / k) + "ms/op.");
function spiral() {
var n = 1e4,
dy = 5;
var spiral = d3.range(0, 1 + 1 / n, 1 / n).map(function(t) {
return [(360 * 10 * t) % 360 - 180, -90 + dy + (90 - dy) * 2 * t];
}).concat(d3.range(1, 0, -1 / n).map(function(t) {
return [(360 * 10 * t) % 360 - 180, -90 + (90 - dy) * 2 * t];
}));
spiral.push(spiral[0]);
return {type: "Polygon", coordinates: [spiral]};
}