-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.js
75 lines (71 loc) · 2.32 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
65
66
67
68
69
70
71
72
73
74
75
var fs = require("fs");
var Benchmark = require("benchmark");
var memwatch = require('memwatch');
var Mask = require("./mask");
function readMask (path, callback) {
var rs = fs.createReadStream(path);
rs.on("readable", function () {
var buffer = rs.read();
var ab = new ArrayBuffer(buffer.length);
var u8 = new Uint8Array(ab);
for (var i = 0; i < buffer.length; i++) {
u8[i] = buffer[i];
}
var m = new Mask.PBM();
return m.load(ab, callback);
});
}
function readBoth (a, b, done) {
readMask(a, function (a_) {
readMask(b, function (b_) {
return done(a_, b_);
});
});
}
var hd = new memwatch.HeapDiff();
readMask("test-data/frame-10-10-ascii.pbm",
function (_a) {
var diff = hd.end();
console.log("Reading \"frame-10-10-ascii.pbm\" costs",
diff.change.size + ".");
});
var frame = "test-data/frame-10-10-ascii.pbm";
var dot = "test-data/dot-10-10-ascii.pbm";
readBoth(frame, dot, function (frame_, dot_) {
new Benchmark.Suite().
add("Mask.collision [frame@0/0, dot@0/0 ]", function () {
Mask.collision(frame_, dot_);
}).
add("Mask.collision [frame@9/9, dot@0/0 ]", function () {
Mask.collision(frame_.at(9, 9), dot_);
}).
add("Mask.collision [dot@0/0, frame@9/9 ]", function () {
Mask.collision(dot_, frame_.at(9, 9));
}).
add("Mask.collision [frame@0/0, bounding]", function () {
Mask.collision(frame_, Mask.Box.bounding(frame_));
}).
add("Mask.collision [dot@0/0, bounding ]", function () {
Mask.collision(dot_, Mask.Box.bounding(dot_));
}).
add("Mask.collision [10/10@0/0, 2/2@0/0 ]", function () {
Mask.collision(new Mask.Box(10, 10),
new Mask.Box(2, 2));
}).
add("Mask.collision [2/2@0/0, 10/10@0/0 ]", function () {
Mask.collision(new Mask.Box(2, 2),
new Mask.Box(10, 10));
}).
add("Mask.collision [2/2@2/2, 4/4@0/0 ]", function () {
Mask.collision(new Mask.Box(2, 2).at(2, 2),
new Mask.Box(4, 4));
}).
add("Mask.collision [6/6@12/12, 6/6@0/0 ]", function () {
Mask.collision(new Mask.Box(6, 6).at(12, 12),
new Mask.Box(6, 6));
}).
on("cycle", function (event) {
console.log(event.target.toString());
}).
run();
});