-
Notifications
You must be signed in to change notification settings - Fork 610
/
Copy pathbench.js
executable file
·63 lines (55 loc) · 1.66 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
#!/usr/bin/env node
let Benchmark = require("benchmark"),
sprintf = require("sprintf").sprintf;
let Graph = require("graphlib").Graph,
rank = require("../lib/rank"),
layout = require("..").layout;
function runBenchmark(name, fn) {
let options = {};
options.onComplete = function(bench) {
let target = bench.target,
hz = target.hz,
stats = target.stats,
rme = stats.rme,
samples = stats.sample.length,
msg = sprintf(" %25s: %13s ops/sec \xb1 %s%% (%3d run(s) sampled)",
target.name,
Benchmark.formatNumber(hz.toFixed(2)),
rme.toFixed(2),
samples);
console.log(msg);
};
options.onError = function(bench) {
console.error(" " + bench.target.error);
};
options.setup = function() {
this.count = Math.random() * 1000;
this.nextInt = function(range) {
return Math.floor(this.count++ % range );
};
};
new Benchmark(name, fn, options).run();
}
let g = new Graph()
.setGraph({})
.setDefaultNodeLabel(function() { return { width: 1, height: 1}; })
.setDefaultEdgeLabel(function() { return { minlen: 1, weight: 1 }; })
.setPath(["a", "b", "c", "d", "h"])
.setPath(["a", "e", "g", "h"])
.setPath(["a", "f", "g"]);
runBenchmark("longest-path ranker", function() {
g.graph().ranker = "longest-path";
rank(g);
});
runBenchmark("tight-tree ranker", function() {
g.graph().ranker = "tight-tree";
rank(g);
});
runBenchmark("network-simplex ranker", function() {
g.graph().ranker = "network-simplex";
rank(g);
});
runBenchmark("layout", function() {
delete g.graph().ranker;
layout(g);
});