Skip to content

Commit 5330caa

Browse files
committed
chore: add benchmark framework with tatami-ng
1 parent cd1fbea commit 5330caa

2 files changed

Lines changed: 105 additions & 0 deletions

File tree

benchmarks/index.bench.ts

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env node --import tsx
2+
/**
3+
* CLI Progress Reporting Benchmarks
4+
*
5+
* Measures performance of core operations using tatami-ng for statistical rigor.
6+
*
7+
* Run: npm run bench
8+
*
9+
* See: /docs/BENCHMARKING_STANDARDS.md
10+
*/
11+
12+
import { bench, baseline, group, run } from 'tatami-ng';
13+
import { ProgressReporter, ProgressState } from '../src/index.ts';
14+
import { mkdtempSync, rmSync } from 'node:fs';
15+
import { tmpdir } from 'node:os';
16+
import { join } from 'node:path';
17+
18+
// Prevent dead code elimination
19+
let result: ProgressReporter | ProgressState | undefined;
20+
let tempDir: string;
21+
22+
// Setup/teardown
23+
function setup() {
24+
tempDir = mkdtempSync(join(tmpdir(), 'prog-bench-'));
25+
}
26+
27+
function teardown() {
28+
if (tempDir) {
29+
rmSync(tempDir, { recursive: true, force: true });
30+
}
31+
}
32+
33+
// ============================================================================
34+
// Core Operations Benchmarks
35+
// ============================================================================
36+
37+
group('Progress Reporter Creation', () => {
38+
setup();
39+
40+
baseline('create: basic reporter', () => {
41+
result = new ProgressReporter({
42+
total: 100,
43+
stateDir: tempDir,
44+
});
45+
});
46+
47+
bench('create: with custom message', () => {
48+
result = new ProgressReporter({
49+
total: 100,
50+
message: 'Processing files',
51+
stateDir: tempDir,
52+
});
53+
});
54+
55+
teardown();
56+
});
57+
58+
group('Progress Updates', () => {
59+
setup();
60+
const reporter = new ProgressReporter({
61+
total: 1000,
62+
stateDir: tempDir,
63+
});
64+
65+
baseline('update: increment', () => {
66+
reporter.increment();
67+
});
68+
69+
bench('update: set progress', () => {
70+
reporter.setProgress(500);
71+
});
72+
73+
bench('update: with message', () => {
74+
reporter.setMessage('Step 500 of 1000');
75+
});
76+
77+
teardown();
78+
});
79+
80+
group('State Reading', () => {
81+
setup();
82+
const reporter = new ProgressReporter({
83+
total: 100,
84+
stateDir: tempDir,
85+
});
86+
reporter.setProgress(50);
87+
88+
baseline('read: get state', () => {
89+
result = reporter.getState();
90+
});
91+
92+
teardown();
93+
});
94+
95+
// ============================================================================
96+
// Run Benchmarks
97+
// ============================================================================
98+
99+
await run({
100+
units: false,
101+
silent: false,
102+
json: false,
103+
});

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"test:filesystem": "node --import tsx --test test/filesystem.test.ts",
1717
"test:fuzzy": "node --import tsx --test test/fuzzy.test.ts",
1818
"test:watch": "node --import tsx --test --watch test/index.test.ts test/cli.test.ts test/filesystem.test.ts test/fuzzy.test.ts",
19+
"bench": "node --import tsx benchmarks/index.bench.ts",
1920
"dogfood": "npm run dogfood:flaky",
2021
"dogfood:flaky": "flaky --test 'npm test' --runs 10"
2122
},
@@ -42,6 +43,7 @@
4243
"devDependencies": {
4344
"@tuulbelt/test-flakiness-detector": "git+https://github.com/tuulbelt/test-flakiness-detector.git",
4445
"@types/node": "^20.19.27",
46+
"tatami-ng": "^0.8.0",
4547
"tsx": "^4.7.0",
4648
"typescript": "^5.3.0"
4749
}

0 commit comments

Comments
 (0)