-
Notifications
You must be signed in to change notification settings - Fork 1
/
bench-it.js
executable file
·51 lines (42 loc) · 1.37 KB
/
bench-it.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
#!/usr/bin/env node
const { execSync } = require('child_process');
const fs = require('fs');
const NODEJS_PACKAGE_BENCHMARK_PATH = __dirname;
if (process.argv.length < 3) {
console.log("You must pass the binary as argument. Example: bench-it ./node");
process.exit(1);
}
const BINARY = process.argv[2];
if (process.argv[3] === "baseline") {
const result = execSync(`${BINARY} --allow-natives-syntax ${NODEJS_PACKAGE_BENCHMARK_PATH}/index.js`, {
env: { TTY: true },
}).toString();
fs.writeFileSync('baseline.out', `${result}`);
console.log("Baseline generated.");
process.exit(0);
}
if (!fs.existsSync('./baseline.out')) {
console.log(`The baseline.out does not exist. Generate it with: $ bench-it ${BINARY} baseline.`);
process.exit(1);
}
let diffCmd = "colordiff";
try {
execSync("command -v colordiff");
} catch (error) {
console.log("⚠️ 'colordiff' was not found. Using 'diff' as fallback.");
diffCmd = "diff";
}
const currentResult = execSync(`${BINARY} --allow-natives-syntax ${NODEJS_PACKAGE_BENCHMARK_PATH}/index.js`, {
env: { TTY: true },
}).toString();
fs.writeFileSync('current.out', currentResult);
try {
const stdout = execSync(`${diffCmd} -y baseline.out current.out`, {
cwd: process.cwd()
})
console.log(stdout.toString())
} catch (e) {
// `diff` returns a non-0 exit code
console.log(e.message)
console.log(e.stdout.toString())
}