-
Notifications
You must be signed in to change notification settings - Fork 9
/
benchmark.js
67 lines (55 loc) · 1.61 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
#!/usr/bin/env node
"use strict";
/* eslint-disable no-console */
let fs = require("fs");
let rimraf = require("rimraf");
let MergeTrees = require("./");
rimraf.sync("tmp");
fs.mkdirSync("tmp");
makeInputDir("tmp/input1", 2, 2);
makeInputDir("tmp/input2", 3, 3);
makeInputDir("tmp/input3", 5, 3);
let inputPaths = ["tmp/input1", "tmp/input2", "tmp/input3"];
function makeInputDir(p, modulo, depth) {
fs.mkdirSync(p);
for (let i = 0; i < 100; i++) {
if (i % modulo !== 0) continue;
fs.writeFileSync(`${p}/file${i}`, `file ${i} contents`);
if (depth > 1) {
makeInputDir(`${p}/dir${i}`, module, depth - 1);
}
}
}
function modifyInput(i) {
fs.writeFileSync(
`tmp/input${i % 2 ? 1 : 3}/dir0/file0`,
`${i % 4 < 2 ? "_" : ""}` // force size change
);
}
let n = 100;
[false, null].forEach(canSymlink => {
console.time(`initial merge, canSymlink=${canSymlink}`);
for (let i = 0; i < n; i++) {
fs.mkdirSync("tmp/out");
let mergeTrees = new MergeTrees(inputPaths, "tmp/out", {
overwrite: true,
_fsUpdaterOptions: { canSymlink: canSymlink }
});
mergeTrees.merge();
rimraf.sync("tmp/out");
}
console.timeEnd(`initial merge, canSymlink=${canSymlink}`);
console.time(`incremental merge, canSymlink=${canSymlink}`);
fs.mkdirSync("tmp/out");
let mergeTrees = new MergeTrees(inputPaths, "tmp/out", {
overwrite: true,
_fsUpdaterOptions: { canSymlink: canSymlink }
});
for (let i = 0; i < n; i++) {
modifyInput(i);
mergeTrees.merge();
}
rimraf.sync("tmp/out");
console.timeEnd(`incremental merge, canSymlink=${canSymlink}`);
});
rimraf.sync("tmp");