-
Notifications
You must be signed in to change notification settings - Fork 60
/
benchmark.js
102 lines (88 loc) · 2.76 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const cp = require('child_process');
const path = require('path');
const os = require('os');
let noDaemon = process.argv[2] === 'no-daemon';
const NUMBER_OF_RUNS = 10;
function message(m) {
console.log('------------------------');
console.log(m);
console.log('------------------------');
}
function cleanFolders() {
// uncomment this to remove all artifacts after every run
// cp.execSync(
// 'rm -rf apps/crew/.next && rm -rf apps/flight-simulator/.next && rm -rf apps/navigation/.next && rm -rf apps/ticket-booking/.next && rm -rf apps/warp-drive-manager/.next'
// );
}
function spawnSync(cmd, args) {
return cp.spawnSync(
path.join(
'.',
'node_modules',
'.bin',
os.platform() === 'win32' ? cmd + '.cmd' : cmd
),
args,
{
stdio: 'inherit',
env: {
...process.env,
NX_TASKS_RUNNER_DYNAMIC_OUTPUT: 'false',
NX_DAEMON: !noDaemon,
},
}
);
}
if (noDaemon) {
message('Running without daemons');
}
message('prepping turbo');
let turboArgs = ['run', 'build', `--concurrency=10`]
if (noDaemon) {
turboArgs.push('--no-daemon')
}
spawnSync('turbo', turboArgs);
message(`running turbo ${NUMBER_OF_RUNS} times`);
let turboTime = 0;
for (let i = 0; i < NUMBER_OF_RUNS; ++i) {
cleanFolders();
const b = new Date();
spawnSync('turbo', turboArgs);
const a = new Date();
turboTime += a.getTime() - b.getTime();
console.log(`The command ran in ${a.getTime() - b.getTime()}ms`);
}
const averageTurboTime = turboTime / NUMBER_OF_RUNS;
message('prepping nx');
spawnSync('nx', ['run-many', '-t', 'build']);
message(`running nx ${NUMBER_OF_RUNS} times`);
let nxTime = 0;
for (let i = 0; i < NUMBER_OF_RUNS; ++i) {
cleanFolders();
const b = new Date();
spawnSync('nx', ['run-many', '-t', 'build', '--parallel', 10]);
const a = new Date();
nxTime += a.getTime() - b.getTime();
console.log(`The command ran in ${a.getTime() - b.getTime()}ms`);
}
const averageNxTime = nxTime / NUMBER_OF_RUNS;
message('prepping lage');
spawnSync('lage', ['build', '--concurrency', 3]);
message(`running lage ${NUMBER_OF_RUNS} times`);
let lageTime = 0;
for (let i = 0; i < NUMBER_OF_RUNS; ++i) {
cleanFolders();
const b = new Date();
spawnSync('lage', ['build', '--concurrency', 10]);
const a = new Date();
lageTime += a.getTime() - b.getTime();
console.log(`The command ran in ${a.getTime() - b.getTime()}ms`);
}
const averageLageTime =
lageTime / NUMBER_OF_RUNS;
message('results');
console.log(`average lage time is: ${averageLageTime}`);
console.log(`average turbo time is: ${averageTurboTime}`);
console.log(`average nx time is: ${averageNxTime}`);
console.log(`nx is ${averageLageTime / averageNxTime}x faster than lage`);
console.log(`nx is ${averageTurboTime / averageNxTime}x faster than turbo`);