-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcompletion.bench.ts
More file actions
62 lines (49 loc) · 1.45 KB
/
completion.bench.ts
File metadata and controls
62 lines (49 loc) · 1.45 KB
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
import { Bench } from 'tinybench';
import { promisify } from 'node:util';
import { exec as execCb } from 'node:child_process';
const exec = promisify(execCb);
const bench = new Bench({ time: 2000 });
const cmdPrefix = `${process.execPath} ./dist/examples/demo.t.js complete --`;
async function run(cmd: string) {
await exec(cmd);
}
bench.add('command completion', async () => {
await run(`${cmdPrefix} d`);
});
bench.add('option completion', async () => {
await run(`${cmdPrefix} dev --p`);
});
bench.add('option value completion', async () => {
await run(`${cmdPrefix} dev --port ""`);
});
bench.add('config value completion', async () => {
await run(`${cmdPrefix} --config ""`);
});
bench.add('no match', async () => {
await run(`${cmdPrefix} xyz`);
});
async function runBenchmarks() {
await bench.run();
console.table(
bench.tasks.map((task) => {
const hz = task.result?.hz;
const derivedMs =
typeof hz === 'number' && hz > 0 ? 1000 / hz : undefined;
const mean = task.result?.mean;
return {
name: task.name,
'ops/sec': hz ? Math.round(hz).toLocaleString() : 'N/A',
'avg (ms)':
derivedMs !== undefined
? derivedMs.toFixed(3)
: mean !== undefined
? (mean * 1000).toFixed(3)
: 'N/A',
};
})
);
}
if (process.argv[1]?.endsWith('completion.bench.ts')) {
runBenchmarks().catch(console.error);
}
export { runBenchmarks };