|
| 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 | +}); |
0 commit comments