modestbench 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +39 -31
- package/dist/bootstrap.cjs +10 -10
- package/dist/bootstrap.cjs.map +1 -1
- package/dist/bootstrap.d.cts.map +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +5 -5
- package/dist/bootstrap.js.map +1 -1
- package/dist/cli/commands/history.cjs +108 -266
- package/dist/cli/commands/history.cjs.map +1 -1
- package/dist/cli/commands/history.d.cts +75 -12
- package/dist/cli/commands/history.d.cts.map +1 -1
- package/dist/cli/commands/history.d.ts +75 -12
- package/dist/cli/commands/history.d.ts.map +1 -1
- package/dist/cli/commands/history.js +105 -268
- package/dist/cli/commands/history.js.map +1 -1
- package/dist/cli/commands/run.cjs +18 -5
- package/dist/cli/commands/run.cjs.map +1 -1
- package/dist/cli/commands/run.d.cts +1 -0
- package/dist/cli/commands/run.d.cts.map +1 -1
- package/dist/cli/commands/run.d.ts +1 -0
- package/dist/cli/commands/run.d.ts.map +1 -1
- package/dist/cli/commands/run.js +18 -5
- package/dist/cli/commands/run.js.map +1 -1
- package/dist/cli/index.cjs +307 -91
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +308 -92
- package/dist/cli/index.js.map +1 -1
- package/dist/core/engine.cjs +8 -1
- package/dist/core/engine.cjs.map +1 -1
- package/dist/core/engine.d.cts +3 -0
- package/dist/core/engine.d.cts.map +1 -1
- package/dist/core/engine.d.ts +3 -0
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/core/engine.js +8 -1
- package/dist/core/engine.js.map +1 -1
- package/dist/core/output-path-resolver.cjs +34 -0
- package/dist/core/output-path-resolver.cjs.map +1 -0
- package/dist/core/output-path-resolver.d.cts +10 -0
- package/dist/core/output-path-resolver.d.cts.map +1 -0
- package/dist/core/output-path-resolver.d.ts +10 -0
- package/dist/core/output-path-resolver.d.ts.map +1 -0
- package/dist/core/output-path-resolver.js +30 -0
- package/dist/core/output-path-resolver.js.map +1 -0
- package/dist/formatters/history/base.cjs +9 -0
- package/dist/formatters/history/base.cjs.map +1 -0
- package/dist/formatters/history/base.d.cts +26 -0
- package/dist/formatters/history/base.d.cts.map +1 -0
- package/dist/formatters/history/base.d.ts +26 -0
- package/dist/formatters/history/base.d.ts.map +1 -0
- package/dist/formatters/history/base.js +8 -0
- package/dist/formatters/history/base.js.map +1 -0
- package/dist/formatters/history/compare.cjs +127 -0
- package/dist/formatters/history/compare.cjs.map +1 -0
- package/dist/formatters/history/compare.d.cts +21 -0
- package/dist/formatters/history/compare.d.cts.map +1 -0
- package/dist/formatters/history/compare.d.ts +21 -0
- package/dist/formatters/history/compare.d.ts.map +1 -0
- package/dist/formatters/history/compare.js +123 -0
- package/dist/formatters/history/compare.js.map +1 -0
- package/dist/formatters/history/list.cjs +74 -0
- package/dist/formatters/history/list.cjs.map +1 -0
- package/dist/formatters/history/list.d.cts +25 -0
- package/dist/formatters/history/list.d.cts.map +1 -0
- package/dist/formatters/history/list.d.ts +25 -0
- package/dist/formatters/history/list.d.ts.map +1 -0
- package/dist/formatters/history/list.js +70 -0
- package/dist/formatters/history/list.js.map +1 -0
- package/dist/formatters/history/show.cjs +98 -0
- package/dist/formatters/history/show.cjs.map +1 -0
- package/dist/formatters/history/show.d.cts +21 -0
- package/dist/formatters/history/show.d.cts.map +1 -0
- package/dist/formatters/history/show.d.ts +21 -0
- package/dist/formatters/history/show.d.ts.map +1 -0
- package/dist/formatters/history/show.js +94 -0
- package/dist/formatters/history/show.js.map +1 -0
- package/dist/formatters/history/trends.cjs +194 -0
- package/dist/formatters/history/trends.cjs.map +1 -0
- package/dist/formatters/history/trends.d.cts +22 -0
- package/dist/formatters/history/trends.d.cts.map +1 -0
- package/dist/formatters/history/trends.d.ts +22 -0
- package/dist/formatters/history/trends.d.ts.map +1 -0
- package/dist/formatters/history/trends.js +190 -0
- package/dist/formatters/history/trends.js.map +1 -0
- package/dist/formatters/history/visualization.cjs +79 -0
- package/dist/formatters/history/visualization.cjs.map +1 -0
- package/dist/formatters/history/visualization.d.cts +24 -0
- package/dist/formatters/history/visualization.d.cts.map +1 -0
- package/dist/formatters/history/visualization.d.ts +24 -0
- package/dist/formatters/history/visualization.d.ts.map +1 -0
- package/dist/formatters/history/visualization.js +74 -0
- package/dist/formatters/history/visualization.js.map +1 -0
- package/dist/index.cjs +15 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -9
- package/dist/index.js.map +1 -1
- package/dist/reporters/csv.cjs +2 -2
- package/dist/reporters/csv.cjs.map +1 -1
- package/dist/reporters/csv.d.cts +1 -1
- package/dist/reporters/csv.d.cts.map +1 -1
- package/dist/reporters/csv.d.ts +1 -1
- package/dist/reporters/csv.d.ts.map +1 -1
- package/dist/reporters/csv.js +1 -1
- package/dist/reporters/csv.js.map +1 -1
- package/dist/reporters/human.cjs +24 -62
- package/dist/reporters/human.cjs.map +1 -1
- package/dist/reporters/human.d.cts +1 -1
- package/dist/reporters/human.d.cts.map +1 -1
- package/dist/reporters/human.d.ts +1 -1
- package/dist/reporters/human.d.ts.map +1 -1
- package/dist/reporters/human.js +2 -40
- package/dist/reporters/human.js.map +1 -1
- package/dist/reporters/json.cjs +2 -2
- package/dist/reporters/json.cjs.map +1 -1
- package/dist/reporters/json.d.cts +1 -1
- package/dist/reporters/json.d.cts.map +1 -1
- package/dist/reporters/json.d.ts +1 -1
- package/dist/reporters/json.d.ts.map +1 -1
- package/dist/reporters/json.js +1 -1
- package/dist/reporters/json.js.map +1 -1
- package/dist/reporters/simple.cjs +2 -2
- package/dist/reporters/simple.cjs.map +1 -1
- package/dist/reporters/simple.d.cts +1 -1
- package/dist/reporters/simple.d.cts.map +1 -1
- package/dist/reporters/simple.d.ts +1 -1
- package/dist/reporters/simple.d.ts.map +1 -1
- package/dist/reporters/simple.js +1 -1
- package/dist/reporters/simple.js.map +1 -1
- package/dist/{config/manager.cjs → services/config-manager.cjs} +2 -2
- package/dist/services/config-manager.cjs.map +1 -0
- package/dist/{config/manager.d.cts → services/config-manager.d.cts} +1 -1
- package/dist/services/config-manager.d.cts.map +1 -0
- package/dist/{config/manager.d.ts → services/config-manager.d.ts} +1 -1
- package/dist/services/config-manager.d.ts.map +1 -0
- package/dist/{config/manager.js → services/config-manager.js} +2 -2
- package/dist/services/config-manager.js.map +1 -0
- package/dist/{core/loader.cjs → services/file-loader.cjs} +2 -2
- package/dist/services/file-loader.cjs.map +1 -0
- package/dist/{core/loader.d.cts → services/file-loader.d.cts} +1 -1
- package/dist/services/file-loader.d.cts.map +1 -0
- package/dist/{core/loader.d.ts → services/file-loader.d.ts} +1 -1
- package/dist/services/file-loader.d.ts.map +1 -0
- package/dist/{core/loader.js → services/file-loader.js} +2 -2
- package/dist/services/file-loader.js.map +1 -0
- package/dist/services/history/comparison.cjs +124 -0
- package/dist/services/history/comparison.cjs.map +1 -0
- package/dist/services/history/comparison.d.cts +18 -0
- package/dist/services/history/comparison.d.cts.map +1 -0
- package/dist/services/history/comparison.d.ts +18 -0
- package/dist/services/history/comparison.d.ts.map +1 -0
- package/dist/services/history/comparison.js +120 -0
- package/dist/services/history/comparison.js.map +1 -0
- package/dist/services/history/models.cjs +9 -0
- package/dist/services/history/models.cjs.map +1 -0
- package/dist/services/history/models.d.cts +139 -0
- package/dist/services/history/models.d.cts.map +1 -0
- package/dist/services/history/models.d.ts +139 -0
- package/dist/services/history/models.d.ts.map +1 -0
- package/dist/services/history/models.js +8 -0
- package/dist/services/history/models.js.map +1 -0
- package/dist/services/history/query.cjs +97 -0
- package/dist/services/history/query.cjs.map +1 -0
- package/dist/services/history/query.d.cts +38 -0
- package/dist/services/history/query.d.cts.map +1 -0
- package/dist/services/history/query.d.ts +38 -0
- package/dist/services/history/query.d.ts.map +1 -0
- package/dist/services/history/query.js +92 -0
- package/dist/services/history/query.js.map +1 -0
- package/dist/services/history/trend-analysis.cjs +187 -0
- package/dist/services/history/trend-analysis.cjs.map +1 -0
- package/dist/services/history/trend-analysis.d.cts +34 -0
- package/dist/services/history/trend-analysis.d.cts.map +1 -0
- package/dist/services/history/trend-analysis.d.ts +34 -0
- package/dist/services/history/trend-analysis.d.ts.map +1 -0
- package/dist/services/history/trend-analysis.js +179 -0
- package/dist/services/history/trend-analysis.js.map +1 -0
- package/dist/{storage/history.cjs → services/history-storage.cjs} +1 -1
- package/dist/services/history-storage.cjs.map +1 -0
- package/dist/{storage/history.d.cts → services/history-storage.d.cts} +1 -1
- package/dist/services/history-storage.d.cts.map +1 -0
- package/dist/{storage/history.d.ts → services/history-storage.d.ts} +1 -1
- package/dist/services/history-storage.d.ts.map +1 -0
- package/dist/{storage/history.js → services/history-storage.js} +1 -1
- package/dist/services/history-storage.js.map +1 -0
- package/dist/{progress/manager.cjs → services/progress-manager.cjs} +1 -1
- package/dist/services/progress-manager.cjs.map +1 -0
- package/dist/{progress/manager.d.cts → services/progress-manager.d.cts} +1 -1
- package/dist/services/progress-manager.d.cts.map +1 -0
- package/dist/{progress/manager.d.ts → services/progress-manager.d.ts} +1 -1
- package/dist/services/progress-manager.d.ts.map +1 -0
- package/dist/{progress/manager.js → services/progress-manager.js} +1 -1
- package/dist/services/progress-manager.js.map +1 -0
- package/dist/{reporters/registry.cjs → services/reporter-registry.cjs} +1 -1
- package/dist/services/reporter-registry.cjs.map +1 -0
- package/dist/{reporters/registry.d.cts → services/reporter-registry.d.cts} +1 -1
- package/dist/services/reporter-registry.d.cts.map +1 -0
- package/dist/{reporters/registry.d.ts → services/reporter-registry.d.ts} +1 -1
- package/dist/services/reporter-registry.d.ts.map +1 -0
- package/dist/{reporters/registry.js → services/reporter-registry.js} +1 -1
- package/dist/services/reporter-registry.js.map +1 -0
- package/dist/types/cli.d.cts +3 -0
- package/dist/types/cli.d.cts.map +1 -1
- package/dist/types/cli.d.ts +3 -0
- package/dist/types/cli.d.ts.map +1 -1
- package/dist/utils/ansi.cjs +61 -0
- package/dist/utils/ansi.cjs.map +1 -0
- package/dist/utils/ansi.d.cts +53 -0
- package/dist/utils/ansi.d.cts.map +1 -0
- package/dist/utils/ansi.d.ts +53 -0
- package/dist/utils/ansi.d.ts.map +1 -0
- package/dist/utils/ansi.js +57 -0
- package/dist/utils/ansi.js.map +1 -0
- package/package.json +5 -4
- package/src/bootstrap.ts +5 -5
- package/src/cli/commands/history.ts +194 -342
- package/src/cli/commands/run.ts +32 -3
- package/src/cli/index.ts +361 -106
- package/src/core/engine.ts +9 -1
- package/src/core/output-path-resolver.ts +38 -0
- package/src/formatters/history/base.ts +28 -0
- package/src/formatters/history/compare.ts +186 -0
- package/src/formatters/history/list.ts +101 -0
- package/src/formatters/history/show.ts +155 -0
- package/src/formatters/history/trends.ts +281 -0
- package/src/formatters/history/visualization.ts +93 -0
- package/src/index.ts +7 -11
- package/src/reporters/csv.ts +1 -1
- package/src/reporters/human.ts +2 -42
- package/src/reporters/json.ts +1 -1
- package/src/reporters/simple.ts +1 -1
- package/src/{config/manager.ts → services/config-manager.ts} +1 -1
- package/src/{core/loader.ts → services/file-loader.ts} +1 -1
- package/src/services/history/comparison.ts +130 -0
- package/src/services/history/models.ts +148 -0
- package/src/services/history/query.ts +116 -0
- package/src/services/history/trend-analysis.ts +238 -0
- package/src/types/cli.ts +3 -0
- package/src/utils/ansi.ts +59 -0
- package/dist/config/manager.cjs.map +0 -1
- package/dist/config/manager.d.cts.map +0 -1
- package/dist/config/manager.d.ts.map +0 -1
- package/dist/config/manager.js.map +0 -1
- package/dist/core/loader.cjs.map +0 -1
- package/dist/core/loader.d.cts.map +0 -1
- package/dist/core/loader.d.ts.map +0 -1
- package/dist/core/loader.js.map +0 -1
- package/dist/progress/manager.cjs.map +0 -1
- package/dist/progress/manager.d.cts.map +0 -1
- package/dist/progress/manager.d.ts.map +0 -1
- package/dist/progress/manager.js.map +0 -1
- package/dist/reporters/registry.cjs.map +0 -1
- package/dist/reporters/registry.d.cts.map +0 -1
- package/dist/reporters/registry.d.ts.map +0 -1
- package/dist/reporters/registry.js.map +0 -1
- package/dist/storage/history.cjs.map +0 -1
- package/dist/storage/history.d.cts.map +0 -1
- package/dist/storage/history.d.ts.map +0 -1
- package/dist/storage/history.js.map +0 -1
- /package/src/{storage/history.ts → services/history-storage.ts} +0 -0
- /package/src/{progress/manager.ts → services/progress-manager.ts} +0 -0
- /package/src/{reporters/registry.ts → services/reporter-registry.ts} +0 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trends Formatter
|
|
3
|
+
*
|
|
4
|
+
* Formats performance trend analysis with visualizations in human and JSON
|
|
5
|
+
* formats.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { stripVTControlCharacters } from 'node:util';
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
DistributionBucket,
|
|
12
|
+
TrendsResult,
|
|
13
|
+
} from '../../services/history/models.js';
|
|
14
|
+
import type { HistoryFormatter } from './base.js';
|
|
15
|
+
|
|
16
|
+
import { colorize } from '../../utils/ansi.js';
|
|
17
|
+
import { generateBarChart, generateSparkline } from './visualization.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Nanoseconds per millisecond conversion constant
|
|
21
|
+
*/
|
|
22
|
+
const NS_PER_MS = 1_000_000;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Nanoseconds per microsecond conversion constant
|
|
26
|
+
*/
|
|
27
|
+
const NS_PER_US = 1_000;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Intelligently format a time range with appropriate precision Displays
|
|
31
|
+
* microseconds for small values (< 1ms) for better clarity
|
|
32
|
+
*/
|
|
33
|
+
const formatTimeRange = (minNs: number, maxNs: number): string => {
|
|
34
|
+
// If both values are below 1ms, show in microseconds for better precision
|
|
35
|
+
if (maxNs < NS_PER_MS) {
|
|
36
|
+
const minUs = minNs / NS_PER_US;
|
|
37
|
+
const maxUs = maxNs / NS_PER_US;
|
|
38
|
+
return `${minUs.toFixed(2)}-${maxUs.toFixed(2)}µs`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Otherwise show in milliseconds
|
|
42
|
+
const minMs = minNs / NS_PER_MS;
|
|
43
|
+
const maxMs = maxNs / NS_PER_MS;
|
|
44
|
+
return `${minMs.toFixed(3)}-${maxMs.toFixed(3)}ms`;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Calculate visible string length, stripping ANSI escape codes
|
|
49
|
+
*/
|
|
50
|
+
const getVisualLength = (str: string): number =>
|
|
51
|
+
stripVTControlCharacters(str).length;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Formatter for history trends command
|
|
55
|
+
*/
|
|
56
|
+
export class HistoryTrendsFormatter implements HistoryFormatter<TrendsResult> {
|
|
57
|
+
/**
|
|
58
|
+
* Format as human-readable trends with visualizations
|
|
59
|
+
*/
|
|
60
|
+
formatHuman(data: TrendsResult): string {
|
|
61
|
+
const lines: string[] = [];
|
|
62
|
+
|
|
63
|
+
lines.push(
|
|
64
|
+
colorize(
|
|
65
|
+
'brightMagenta',
|
|
66
|
+
colorize('bold', `\nPerformance Trends (${data.runs} runs)`),
|
|
67
|
+
),
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
if (data.timespan.start && data.timespan.end) {
|
|
71
|
+
lines.push(
|
|
72
|
+
colorize(
|
|
73
|
+
'dim',
|
|
74
|
+
`Time range: ${data.timespan.start.toLocaleDateString()} to ${data.timespan.end.toLocaleDateString()}`,
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
lines.push('');
|
|
79
|
+
|
|
80
|
+
// Summary statistics
|
|
81
|
+
lines.push(colorize('brightBlue', 'Summary:'));
|
|
82
|
+
lines.push(
|
|
83
|
+
` ${colorize('brightCyan', '▲')} ${data.summary.improvingTasks} improving ${colorize('brightRed', '▼')} ${data.summary.degradingTasks} degrading ${colorize('dim', '→')} ${data.summary.stableTasks} stable`,
|
|
84
|
+
);
|
|
85
|
+
lines.push('');
|
|
86
|
+
|
|
87
|
+
// Task Performance Summary Table
|
|
88
|
+
lines.push(colorize('brightMagenta', 'Task Performance Summary:'));
|
|
89
|
+
lines.push('');
|
|
90
|
+
|
|
91
|
+
for (const trendData of data.trends) {
|
|
92
|
+
// Show top 20
|
|
93
|
+
const trendIcon =
|
|
94
|
+
trendData.trend === 'improving'
|
|
95
|
+
? colorize('brightCyan', '▲')
|
|
96
|
+
: trendData.trend === 'degrading'
|
|
97
|
+
? colorize('brightRed', '▼')
|
|
98
|
+
: colorize('dim', '→');
|
|
99
|
+
|
|
100
|
+
const changeColor =
|
|
101
|
+
trendData.percentChange < -5
|
|
102
|
+
? 'brightCyan'
|
|
103
|
+
: trendData.percentChange > 5
|
|
104
|
+
? 'brightRed'
|
|
105
|
+
: 'dim';
|
|
106
|
+
|
|
107
|
+
const changeSign = trendData.percentChange >= 0 ? '+' : '';
|
|
108
|
+
const changeStr = `${changeSign}${trendData.percentChange.toFixed(1)}%`;
|
|
109
|
+
|
|
110
|
+
// Generate sparkline - scale with number of data points (min 12, max 20)
|
|
111
|
+
const values = trendData.dataPoints.map((dp) => dp.mean);
|
|
112
|
+
const sparklineWidth = Math.min(20, Math.max(12, trendData.runs));
|
|
113
|
+
const sparkline = generateSparkline(values, sparklineWidth);
|
|
114
|
+
const sparklineColor =
|
|
115
|
+
trendData.trend === 'improving'
|
|
116
|
+
? 'brightCyan'
|
|
117
|
+
: trendData.trend === 'degrading'
|
|
118
|
+
? 'brightRed'
|
|
119
|
+
: 'cyan';
|
|
120
|
+
|
|
121
|
+
const taskName = colorize('white', trendData.task);
|
|
122
|
+
const percentDisplay = colorize(changeColor, changeStr.padStart(8));
|
|
123
|
+
const sparklineDisplay = colorize(sparklineColor, sparkline);
|
|
124
|
+
|
|
125
|
+
// Layout: icon (2) + task name + padding + percent (8) + spaces (2) + sparkline
|
|
126
|
+
// Position percent+graph at visual column 60 for consistent alignment
|
|
127
|
+
const prefix = ` ${trendIcon} ${taskName}`;
|
|
128
|
+
const prefixVisualLength = getVisualLength(prefix);
|
|
129
|
+
const targetColumn = 60;
|
|
130
|
+
|
|
131
|
+
if (prefixVisualLength > targetColumn) {
|
|
132
|
+
// Task name is too long, wrap to next line
|
|
133
|
+
lines.push(prefix);
|
|
134
|
+
lines.push(
|
|
135
|
+
`${' '.repeat(targetColumn)}${percentDisplay} ${sparklineDisplay}`,
|
|
136
|
+
);
|
|
137
|
+
} else {
|
|
138
|
+
// Fit on one line with padding
|
|
139
|
+
const padding = Math.max(1, targetColumn - prefixVisualLength);
|
|
140
|
+
const paddingStr = ' '.repeat(padding);
|
|
141
|
+
lines.push(
|
|
142
|
+
`${prefix}${paddingStr}${percentDisplay} ${sparklineDisplay}`,
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Show all trends (no limit)
|
|
148
|
+
|
|
149
|
+
lines.push('');
|
|
150
|
+
|
|
151
|
+
// Show regressions if any
|
|
152
|
+
if (data.regressions.length > 0) {
|
|
153
|
+
lines.push(
|
|
154
|
+
colorize('brightRed', colorize('bold', 'Regressions Detected:')),
|
|
155
|
+
);
|
|
156
|
+
lines.push('');
|
|
157
|
+
|
|
158
|
+
for (const regression of data.regressions) {
|
|
159
|
+
lines.push(
|
|
160
|
+
` ${colorize('brightRed', '▼')} ${colorize('white', regression.task)}: ${colorize('brightRed', `${regression.percentChange.toFixed(1)}% slower`)} (${regression.runs} runs)`,
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
lines.push('');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Show low-confidence regressions (insufficient data)
|
|
168
|
+
if (data.lowConfidenceRegressions.length > 0) {
|
|
169
|
+
lines.push(
|
|
170
|
+
colorize(
|
|
171
|
+
'brightYellow',
|
|
172
|
+
colorize('bold', '! Potential Regressions (insufficient data):'),
|
|
173
|
+
),
|
|
174
|
+
);
|
|
175
|
+
lines.push('');
|
|
176
|
+
|
|
177
|
+
for (const regression of data.lowConfidenceRegressions) {
|
|
178
|
+
lines.push(
|
|
179
|
+
` ${colorize('brightYellow', '!')} ${colorize('white', regression.task)}: ${colorize('brightYellow', `${regression.percentChange.toFixed(1)}% slower`)} (${regression.runs} run${regression.runs !== 1 ? 's' : ''})`,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
lines.push('');
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Show performance distribution for most important task (highest RME) if we have enough data
|
|
187
|
+
// Find task with highest relative margin of error - the most variable/unreliable one
|
|
188
|
+
const mostImportantTrend = data.trends
|
|
189
|
+
.filter((t) => t.runs >= 5)
|
|
190
|
+
.sort((a, b) => {
|
|
191
|
+
const rmeA = (a.statistics.stdDeviation / a.statistics.mean) * 100;
|
|
192
|
+
const rmeB = (b.statistics.stdDeviation / b.statistics.mean) * 100;
|
|
193
|
+
return rmeB - rmeA; // Descending order (highest RME first)
|
|
194
|
+
})[0];
|
|
195
|
+
|
|
196
|
+
if (mostImportantTrend) {
|
|
197
|
+
lines.push(
|
|
198
|
+
colorize(
|
|
199
|
+
'brightMagenta',
|
|
200
|
+
'Performance Distribution (most variable task):',
|
|
201
|
+
),
|
|
202
|
+
);
|
|
203
|
+
lines.push(colorize('white', mostImportantTrend.task));
|
|
204
|
+
const cv = (
|
|
205
|
+
(mostImportantTrend.statistics.stdDeviation /
|
|
206
|
+
mostImportantTrend.statistics.mean) *
|
|
207
|
+
100
|
|
208
|
+
).toFixed(1);
|
|
209
|
+
lines.push(colorize('dim', ` Variability: ${cv}%`));
|
|
210
|
+
lines.push('');
|
|
211
|
+
|
|
212
|
+
// Create distribution buckets
|
|
213
|
+
const values = mostImportantTrend.dataPoints.map((dp) => dp.mean);
|
|
214
|
+
const min = Math.min(...values);
|
|
215
|
+
const max = Math.max(...values);
|
|
216
|
+
const range = max - min;
|
|
217
|
+
const numBuckets = Math.min(5, mostImportantTrend.runs);
|
|
218
|
+
const bucketSize = range / numBuckets;
|
|
219
|
+
|
|
220
|
+
const buckets: DistributionBucket[] = [];
|
|
221
|
+
for (let i = 0; i < numBuckets; i++) {
|
|
222
|
+
const bucketMin = min + i * bucketSize;
|
|
223
|
+
const bucketMax = min + (i + 1) * bucketSize;
|
|
224
|
+
const count = values.filter(
|
|
225
|
+
(v) =>
|
|
226
|
+
v >= bucketMin &&
|
|
227
|
+
(i === numBuckets - 1 ? v <= bucketMax : v < bucketMax),
|
|
228
|
+
).length;
|
|
229
|
+
|
|
230
|
+
const label = formatTimeRange(bucketMin, bucketMax);
|
|
231
|
+
|
|
232
|
+
buckets.push({
|
|
233
|
+
count,
|
|
234
|
+
label,
|
|
235
|
+
max: bucketMax,
|
|
236
|
+
min: bucketMin,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Filter out empty buckets for cleaner display
|
|
241
|
+
const nonEmptyBuckets = buckets.filter((b) => b.count > 0);
|
|
242
|
+
const chart = generateBarChart(nonEmptyBuckets, 25);
|
|
243
|
+
for (const line of chart) {
|
|
244
|
+
lines.push(colorize('brightCyan', line));
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
lines.push('');
|
|
248
|
+
lines.push(
|
|
249
|
+
colorize(
|
|
250
|
+
'dim',
|
|
251
|
+
` Mean: ${(mostImportantTrend.statistics.mean / NS_PER_MS).toFixed(3)}ms Median: ${(mostImportantTrend.statistics.median / NS_PER_MS).toFixed(3)}ms StdDev: ${(mostImportantTrend.statistics.stdDeviation / NS_PER_MS).toFixed(3)}ms`,
|
|
252
|
+
),
|
|
253
|
+
);
|
|
254
|
+
lines.push('');
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return lines.join('\n');
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Format as JSON
|
|
262
|
+
*/
|
|
263
|
+
formatJson(data: TrendsResult): string {
|
|
264
|
+
return JSON.stringify(
|
|
265
|
+
{
|
|
266
|
+
regressions: data.regressions,
|
|
267
|
+
summary: {
|
|
268
|
+
degradingTasks: data.summary.degradingTasks,
|
|
269
|
+
improvingTasks: data.summary.improvingTasks,
|
|
270
|
+
runs: data.runs,
|
|
271
|
+
stableTasks: data.summary.stableTasks,
|
|
272
|
+
timespan: data.timespan,
|
|
273
|
+
totalTasks: data.summary.totalTasks,
|
|
274
|
+
},
|
|
275
|
+
trends: data.trends,
|
|
276
|
+
},
|
|
277
|
+
null,
|
|
278
|
+
2,
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Visualization Utilities for History Formatters
|
|
3
|
+
*
|
|
4
|
+
* Pure functions for generating ASCII visualizations (sparklines, bar charts)
|
|
5
|
+
* for trend analysis and performance distribution displays.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { DistributionBucket } from '../../services/history/models.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Generate bar chart histogram from distribution buckets
|
|
12
|
+
*
|
|
13
|
+
* @param distribution - Array of distribution buckets with counts
|
|
14
|
+
* @param maxWidth - Maximum width of bars (default 20)
|
|
15
|
+
* @returns Array of formatted bar chart lines
|
|
16
|
+
*/
|
|
17
|
+
export const generateBarChart = (
|
|
18
|
+
distribution: DistributionBucket[],
|
|
19
|
+
maxWidth = 20,
|
|
20
|
+
): string[] => {
|
|
21
|
+
if (distribution.length === 0) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Find maximum count for scaling
|
|
26
|
+
const maxCount = Math.max(...distribution.map((b) => b.count));
|
|
27
|
+
|
|
28
|
+
if (maxCount === 0) {
|
|
29
|
+
return distribution.map((bucket) => ` ${bucket.label} (0 runs)`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Block characters for bar visualization
|
|
33
|
+
const fullBlock = '█';
|
|
34
|
+
const lightBlock = '░';
|
|
35
|
+
|
|
36
|
+
return distribution.map((bucket) => {
|
|
37
|
+
const ratio = bucket.count / maxCount;
|
|
38
|
+
const barLength = Math.round(ratio * maxWidth);
|
|
39
|
+
const fullBlocks = fullBlock.repeat(barLength);
|
|
40
|
+
const emptyBlocks = lightBlock.repeat(maxWidth - barLength);
|
|
41
|
+
|
|
42
|
+
return ` ${fullBlocks}${emptyBlocks} ${bucket.label} (${bucket.count} run${bucket.count !== 1 ? 's' : ''})`;
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Generate ASCII sparkline from values
|
|
48
|
+
*
|
|
49
|
+
* @param values - Array of numeric values to visualize
|
|
50
|
+
* @param width - Maximum width of sparkline (downsamples if needed)
|
|
51
|
+
* @returns ASCII sparkline string using block characters
|
|
52
|
+
*/
|
|
53
|
+
export const generateSparkline = (values: number[], width?: number): string => {
|
|
54
|
+
if (values.length === 0) {
|
|
55
|
+
return '';
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Sparkline characters from lowest to highest
|
|
59
|
+
const sparkChars = ['▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'];
|
|
60
|
+
|
|
61
|
+
// Downsample if width is specified and values exceed it
|
|
62
|
+
let processedValues = values;
|
|
63
|
+
if (width && values.length > width) {
|
|
64
|
+
const step = values.length / width;
|
|
65
|
+
processedValues = [];
|
|
66
|
+
for (let i = 0; i < width; i++) {
|
|
67
|
+
const idx = Math.floor(i * step);
|
|
68
|
+
processedValues.push(values[idx] ?? 0);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Find min and max for scaling
|
|
73
|
+
const min = Math.min(...processedValues);
|
|
74
|
+
const max = Math.max(...processedValues);
|
|
75
|
+
const range = max - min;
|
|
76
|
+
|
|
77
|
+
// Handle case where all values are the same
|
|
78
|
+
if (range === 0) {
|
|
79
|
+
return (sparkChars[4] ?? '▄').repeat(processedValues.length); // Use middle character
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Map each value to a sparkline character
|
|
83
|
+
return processedValues
|
|
84
|
+
.map((value) => {
|
|
85
|
+
const normalized = (value - min) / range;
|
|
86
|
+
const index = Math.min(
|
|
87
|
+
Math.floor(normalized * sparkChars.length),
|
|
88
|
+
sparkChars.length - 1,
|
|
89
|
+
);
|
|
90
|
+
return sparkChars[index] ?? '▄';
|
|
91
|
+
})
|
|
92
|
+
.join('');
|
|
93
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -7,15 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
export { bootstrap as modestbench } from './bootstrap.js';
|
|
10
|
-
// Configuration management
|
|
11
|
-
export { ModestBenchConfigurationManager } from './config/manager.js';
|
|
12
10
|
|
|
13
|
-
// Core engine
|
|
11
|
+
// Core engine
|
|
14
12
|
export { ModestBenchEngine } from './core/engine.js';
|
|
15
13
|
export { AccurateEngine, TinybenchEngine } from './core/engines/index.js';
|
|
16
14
|
|
|
17
|
-
export { BenchmarkFileLoader } from './core/loader.js';
|
|
18
|
-
|
|
19
15
|
// Statistical utilities
|
|
20
16
|
export {
|
|
21
17
|
calculateStatistics,
|
|
@@ -26,21 +22,21 @@ export {
|
|
|
26
22
|
// Error classes
|
|
27
23
|
export * from './errors/index.js';
|
|
28
24
|
|
|
29
|
-
// Progress tracking
|
|
30
|
-
export { ModestBenchProgressManager } from './progress/manager.js';
|
|
31
25
|
// Reporters
|
|
32
26
|
export { CsvReporter } from './reporters/csv.js';
|
|
33
27
|
export { HumanReporter } from './reporters/human.js';
|
|
34
28
|
export { JsonReporter } from './reporters/json.js';
|
|
35
29
|
|
|
30
|
+
// Services
|
|
31
|
+
export { ModestBenchConfigurationManager } from './services/config-manager.js';
|
|
32
|
+
export { BenchmarkFileLoader } from './services/file-loader.js';
|
|
33
|
+
export { FileHistoryStorage } from './services/history-storage.js';
|
|
34
|
+
export { ModestBenchProgressManager } from './services/progress-manager.js';
|
|
36
35
|
export {
|
|
37
36
|
BaseReporter,
|
|
38
37
|
CompositeReporter,
|
|
39
38
|
ModestBenchReporterRegistry,
|
|
40
|
-
} from './
|
|
41
|
-
|
|
42
|
-
// Storage
|
|
43
|
-
export { FileHistoryStorage } from './storage/history.js';
|
|
39
|
+
} from './services/reporter-registry.js';
|
|
44
40
|
|
|
45
41
|
// Export all types
|
|
46
42
|
export * from './types/index.js';
|
package/src/reporters/csv.ts
CHANGED
|
@@ -18,7 +18,7 @@ import type {
|
|
|
18
18
|
} from '../types/index.js';
|
|
19
19
|
|
|
20
20
|
import { ReporterOutputError } from '../errors/index.js';
|
|
21
|
-
import { BaseReporter } from '
|
|
21
|
+
import { BaseReporter } from '../services/reporter-registry.js';
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* CSV column definitions for task results
|
package/src/reporters/human.ts
CHANGED
|
@@ -15,48 +15,8 @@ import type {
|
|
|
15
15
|
TaskResult,
|
|
16
16
|
} from '../types/index.js';
|
|
17
17
|
|
|
18
|
-
import { BaseReporter } from '
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* ANSI color codes for terminal output
|
|
22
|
-
*/
|
|
23
|
-
const colors = {
|
|
24
|
-
bold: '\x1b[1m',
|
|
25
|
-
brightBlue: '\x1b[94m',
|
|
26
|
-
brightCyan: '\x1b[96m',
|
|
27
|
-
brightMagenta: '\x1b[95m',
|
|
28
|
-
brightRed: '\x1b[91m',
|
|
29
|
-
brightWhite: '\x1b[97m',
|
|
30
|
-
cyan: '\x1b[36m',
|
|
31
|
-
dim: '\x1b[2m',
|
|
32
|
-
gray: '\x1b[90m',
|
|
33
|
-
green: '\x1b[32m',
|
|
34
|
-
magenta: '\x1b[35m',
|
|
35
|
-
red: '\x1b[31m',
|
|
36
|
-
reset: '\x1b[0m',
|
|
37
|
-
underline: '\x1b[4m',
|
|
38
|
-
white: '\x1b[37m',
|
|
39
|
-
} as const;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* CP437-inspired ANSI art characters
|
|
43
|
-
*/
|
|
44
|
-
const ansiChars = {
|
|
45
|
-
approx: '≈',
|
|
46
|
-
// Block elements for gradients
|
|
47
|
-
block: {
|
|
48
|
-
dark: '▓',
|
|
49
|
-
full: '█',
|
|
50
|
-
light: '░',
|
|
51
|
-
medium: '▒',
|
|
52
|
-
},
|
|
53
|
-
bullet: '•',
|
|
54
|
-
// Symbols
|
|
55
|
-
checkmark: '√',
|
|
56
|
-
cross: '×',
|
|
57
|
-
plusMinus: '±',
|
|
58
|
-
smallSquare: '▪',
|
|
59
|
-
} as const;
|
|
18
|
+
import { BaseReporter } from '../services/reporter-registry.js';
|
|
19
|
+
import { ansiChars, colors } from '../utils/ansi.js';
|
|
60
20
|
|
|
61
21
|
/**
|
|
62
22
|
* Human-readable console reporter with colorized output
|
package/src/reporters/json.ts
CHANGED
|
@@ -17,7 +17,7 @@ import type {
|
|
|
17
17
|
} from '../types/index.js';
|
|
18
18
|
|
|
19
19
|
import { ReporterOutputError } from '../errors/index.js';
|
|
20
|
-
import { BaseReporter } from '
|
|
20
|
+
import { BaseReporter } from '../services/reporter-registry.js';
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* JSON output structure for benchmark results
|
package/src/reporters/simple.ts
CHANGED
|
@@ -18,9 +18,9 @@ import type {
|
|
|
18
18
|
ValidationWarning,
|
|
19
19
|
} from '../types/index.js';
|
|
20
20
|
|
|
21
|
+
import { safeParseConfig } from '../config/schema.js';
|
|
21
22
|
import { ErrorCodes } from '../constants.js';
|
|
22
23
|
import { ConfigLoadError, ConfigValidationError } from '../errors/index.js';
|
|
23
|
-
import { safeParseConfig } from './schema.js';
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Get the default reporter based on TTY status and environment
|
|
@@ -22,12 +22,12 @@ import {
|
|
|
22
22
|
BENCHMARK_FILE_EXTENSIONS,
|
|
23
23
|
BENCHMARK_FILE_PATTERN,
|
|
24
24
|
} from '../constants.js';
|
|
25
|
+
import { benchmarkFileSchema } from '../core/benchmark-schema.js';
|
|
25
26
|
import {
|
|
26
27
|
FileDiscoveryError,
|
|
27
28
|
FileLoadError,
|
|
28
29
|
StructureValidationError,
|
|
29
30
|
} from '../errors/index.js';
|
|
30
|
-
import { benchmarkFileSchema } from './benchmark-schema.js';
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* File change notification for watch functionality
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Benchmark Comparison Service
|
|
3
|
+
*
|
|
4
|
+
* Handles comparison logic between two benchmark runs, calculating performance
|
|
5
|
+
* differences and categorizing tasks.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { BenchmarkRun } from '../../types/index.js';
|
|
9
|
+
import type { CompareResult, TaskComparison } from './models.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Service for comparing benchmark runs
|
|
13
|
+
*/
|
|
14
|
+
export class ComparisonService {
|
|
15
|
+
/**
|
|
16
|
+
* Compare two benchmark runs and produce detailed comparison result
|
|
17
|
+
*/
|
|
18
|
+
compareRuns(run1: BenchmarkRun, run2: BenchmarkRun): CompareResult {
|
|
19
|
+
// Build task maps for comparison
|
|
20
|
+
const tasksMap1 = new Map<string, TaskComparison>();
|
|
21
|
+
const tasksMap2 = new Map<string, TaskComparison>();
|
|
22
|
+
|
|
23
|
+
// Extract tasks from run1
|
|
24
|
+
for (const file of run1.files) {
|
|
25
|
+
for (const suite of file.suites) {
|
|
26
|
+
for (const task of suite.tasks) {
|
|
27
|
+
if (!task.error) {
|
|
28
|
+
const key = `${file.filePath}::${suite.name}::${task.name}`;
|
|
29
|
+
tasksMap1.set(key, {
|
|
30
|
+
file: file.filePath,
|
|
31
|
+
inBoth: false,
|
|
32
|
+
percentChange: 0,
|
|
33
|
+
run1: {
|
|
34
|
+
cv: task.cv,
|
|
35
|
+
iterations: task.iterations,
|
|
36
|
+
max: task.max,
|
|
37
|
+
mean: task.mean,
|
|
38
|
+
min: task.min,
|
|
39
|
+
},
|
|
40
|
+
suite: suite.name,
|
|
41
|
+
task: task.name,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Extract tasks from run2 and merge
|
|
49
|
+
for (const file of run2.files) {
|
|
50
|
+
for (const suite of file.suites) {
|
|
51
|
+
for (const task of suite.tasks) {
|
|
52
|
+
if (!task.error) {
|
|
53
|
+
const key = `${file.filePath}::${suite.name}::${task.name}`;
|
|
54
|
+
const existing = tasksMap1.get(key);
|
|
55
|
+
|
|
56
|
+
if (existing && existing.run1) {
|
|
57
|
+
// Task exists in both runs - calculate comparison
|
|
58
|
+
const percentChange =
|
|
59
|
+
((task.mean - existing.run1.mean) / existing.run1.mean) * 100;
|
|
60
|
+
|
|
61
|
+
tasksMap1.set(key, {
|
|
62
|
+
...existing,
|
|
63
|
+
inBoth: true,
|
|
64
|
+
percentChange,
|
|
65
|
+
run2: {
|
|
66
|
+
cv: task.cv,
|
|
67
|
+
iterations: task.iterations,
|
|
68
|
+
max: task.max,
|
|
69
|
+
mean: task.mean,
|
|
70
|
+
min: task.min,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
} else {
|
|
74
|
+
// Task only in run2
|
|
75
|
+
tasksMap2.set(key, {
|
|
76
|
+
file: file.filePath,
|
|
77
|
+
inBoth: false,
|
|
78
|
+
percentChange: 0,
|
|
79
|
+
run2: {
|
|
80
|
+
cv: task.cv,
|
|
81
|
+
iterations: task.iterations,
|
|
82
|
+
max: task.max,
|
|
83
|
+
mean: task.mean,
|
|
84
|
+
min: task.min,
|
|
85
|
+
},
|
|
86
|
+
suite: suite.name,
|
|
87
|
+
task: task.name,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Separate tasks into categories
|
|
96
|
+
const tasksInBoth: TaskComparison[] = [];
|
|
97
|
+
const tasksOnlyIn1: TaskComparison[] = [];
|
|
98
|
+
const tasksOnlyIn2: TaskComparison[] = [];
|
|
99
|
+
|
|
100
|
+
for (const task of tasksMap1.values()) {
|
|
101
|
+
if (task.inBoth) {
|
|
102
|
+
tasksInBoth.push(task);
|
|
103
|
+
} else {
|
|
104
|
+
tasksOnlyIn1.push(task);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
for (const task of tasksMap2.values()) {
|
|
109
|
+
tasksOnlyIn2.push(task);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
run1: {
|
|
114
|
+
endTime: run1.endTime,
|
|
115
|
+
id: run1.id,
|
|
116
|
+
startTime: run1.startTime,
|
|
117
|
+
summary: run1.summary,
|
|
118
|
+
},
|
|
119
|
+
run2: {
|
|
120
|
+
endTime: run2.endTime,
|
|
121
|
+
id: run2.id,
|
|
122
|
+
startTime: run2.startTime,
|
|
123
|
+
summary: run2.summary,
|
|
124
|
+
},
|
|
125
|
+
tasksInBoth,
|
|
126
|
+
tasksOnlyInRun1: tasksOnlyIn1,
|
|
127
|
+
tasksOnlyInRun2: tasksOnlyIn2,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|