Debian Codegraph @

test/benchmark

raw
1 #!/usr/bin/env node
2
3 var d3_array = require("d3-array"),
4 d3_quadtree = require("../");
5
6 var n = 1000000,
7 points1 = new Array(n),
8 points2 = new Array(n);
9
10 for (var j = 0; j < n; ++j) {
11 points1[j] = [Math.random() * 99, Math.random() * 99];
12 }
13
14 for (var j = 0; j < n; ++j) {
15 points2[j] = [points1[j][0] + Math.random(), points1[j][1] + Math.random()];
16 }
17
18 var start = now();
19 var root = d3_quadtree.quadtree().extent([[0, 0], [100, 100]]).addAll(points1);
20 var end = now();
21 console.log("create", Math.round(end - start));
22
23 var start = now();
24 root.visit(function(node, x0, y0, x1, y1) {});
25 var end = now();
26 console.log("iterate", Math.round(end - start));
27
28 var start = now();
29 for (var j = 0, p; j < n; ++j) {
30 root.remove(points1[j]);
31 root.add(points2[j]);
32 }
33 var end = now();
34 console.log("update", Math.round(end - start));
35
36 function now() {
37 var now = process.hrtime();
38 return now[0] * 1e3 + now[1] / 1e6;
39 }