Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
> **Part of [Tuulbelt](https://github.com/tuulbelt/tuulbelt)** — A collection of zero-dependency tools.

# CLI Progress Reporting / `prog`

[![Tests](https://github.com/tuulbelt/cli-progress-reporting/actions/workflows/test.yml/badge.svg)](https://github.com/tuulbelt/cli-progress-reporting/actions/workflows/test.yml)
Expand Down
103 changes: 103 additions & 0 deletions benchmarks/index.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/usr/bin/env node --import tsx
/**
* CLI Progress Reporting Benchmarks
*
* Measures performance of core operations using tatami-ng for statistical rigor.
*
* Run: npm run bench
*
* See: /docs/BENCHMARKING_STANDARDS.md
*/

import { bench, baseline, group, run } from 'tatami-ng';
import { ProgressReporter, ProgressState } from '../src/index.ts';
import { mkdtempSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';

// Prevent dead code elimination
let result: ProgressReporter | ProgressState | undefined;
let tempDir: string;

// Setup/teardown
function setup() {
tempDir = mkdtempSync(join(tmpdir(), 'prog-bench-'));
}

function teardown() {
if (tempDir) {
rmSync(tempDir, { recursive: true, force: true });
}
}

// ============================================================================
// Core Operations Benchmarks
// ============================================================================

group('Progress Reporter Creation', () => {
setup();

baseline('create: basic reporter', () => {
result = new ProgressReporter({
total: 100,
stateDir: tempDir,
});
});

bench('create: with custom message', () => {
result = new ProgressReporter({
total: 100,
message: 'Processing files',
stateDir: tempDir,
});
});

teardown();
});

group('Progress Updates', () => {
setup();
const reporter = new ProgressReporter({
total: 1000,
stateDir: tempDir,
});

baseline('update: increment', () => {
reporter.increment();
});

bench('update: set progress', () => {
reporter.setProgress(500);
});

bench('update: with message', () => {
reporter.setMessage('Step 500 of 1000');
});

teardown();
});

group('State Reading', () => {
setup();
const reporter = new ProgressReporter({
total: 100,
stateDir: tempDir,
});
reporter.setProgress(50);

baseline('read: get state', () => {
result = reporter.getState();
});

teardown();
});

// ============================================================================
// Run Benchmarks
// ============================================================================

await run({
units: false,
silent: false,
json: false,
});
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"test:filesystem": "node --import tsx --test test/filesystem.test.ts",
"test:fuzzy": "node --import tsx --test test/fuzzy.test.ts",
"test:watch": "node --import tsx --test --watch test/index.test.ts test/cli.test.ts test/filesystem.test.ts test/fuzzy.test.ts",
"bench": "node --import tsx benchmarks/index.bench.ts",
"dogfood": "npm run dogfood:flaky",
"dogfood:flaky": "flaky --test 'npm test' --runs 10"
},
Expand All @@ -42,6 +43,7 @@
"devDependencies": {
"@tuulbelt/test-flakiness-detector": "git+https://github.com/tuulbelt/test-flakiness-detector.git",
"@types/node": "^20.19.27",
"tatami-ng": "^0.8.0",
"tsx": "^4.7.0",
"typescript": "^5.3.0"
}
Expand Down