modestbench 0.7.0 → 0.9.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 +25 -0
- package/README.md +37 -4
- package/dist/adapters/types.d.cts +1 -1
- package/dist/adapters/types.d.cts.map +1 -1
- package/dist/adapters/types.d.ts +1 -1
- package/dist/adapters/types.d.ts.map +1 -1
- package/dist/cli/commands/run.cjs +93 -49
- 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 +95 -51
- package/dist/cli/commands/run.js.map +1 -1
- package/dist/cli/index.cjs +7 -1
- 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 +7 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/{core → config}/benchmark-schema.cjs +1 -1
- package/dist/config/benchmark-schema.cjs.map +1 -0
- package/dist/config/benchmark-schema.d.cts +913 -0
- package/dist/config/benchmark-schema.d.cts.map +1 -0
- package/dist/config/benchmark-schema.d.ts +913 -0
- package/dist/config/benchmark-schema.d.ts.map +1 -0
- package/dist/{core → config}/benchmark-schema.js +1 -1
- package/dist/config/benchmark-schema.js.map +1 -0
- package/dist/config/schema.cjs +188 -105
- package/dist/config/schema.cjs.map +1 -1
- package/dist/config/schema.d.cts +208 -80
- package/dist/config/schema.d.cts.map +1 -1
- package/dist/config/schema.d.ts +208 -80
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config/schema.js +187 -104
- package/dist/config/schema.js.map +1 -1
- package/dist/constants.cjs +2 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +2 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.ts +2 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -0
- package/dist/constants.js.map +1 -1
- package/dist/core/engine.cjs +50 -45
- package/dist/core/engine.cjs.map +1 -1
- package/dist/core/engine.d.cts.map +1 -1
- package/dist/core/engine.d.ts.map +1 -1
- package/dist/core/engine.js +50 -45
- package/dist/core/engine.js.map +1 -1
- package/dist/core/output-path-resolver.cjs +15 -1
- package/dist/core/output-path-resolver.cjs.map +1 -1
- package/dist/core/output-path-resolver.d.cts +8 -0
- package/dist/core/output-path-resolver.d.cts.map +1 -1
- package/dist/core/output-path-resolver.d.ts +8 -0
- package/dist/core/output-path-resolver.d.ts.map +1 -1
- package/dist/core/output-path-resolver.js +13 -0
- package/dist/core/output-path-resolver.js.map +1 -1
- package/dist/errors/index.cjs +3 -1
- package/dist/errors/index.cjs.map +1 -1
- package/dist/errors/index.d.cts +1 -1
- package/dist/errors/index.d.cts.map +1 -1
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/errors/reporter.cjs +45 -1
- package/dist/errors/reporter.cjs.map +1 -1
- package/dist/errors/reporter.d.cts +32 -0
- package/dist/errors/reporter.d.cts.map +1 -1
- package/dist/errors/reporter.d.ts +32 -0
- package/dist/errors/reporter.d.ts.map +1 -1
- package/dist/errors/reporter.js +42 -0
- package/dist/errors/reporter.js.map +1 -1
- package/dist/index.cjs +16 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/reporters/json.cjs +1 -1
- package/dist/reporters/json.cjs.map +1 -1
- package/dist/reporters/json.js +1 -1
- package/dist/reporters/json.js.map +1 -1
- package/dist/schema/modestbench-config.schema.json +94 -87
- package/dist/services/budget-evaluator.cjs +8 -6
- package/dist/services/budget-evaluator.cjs.map +1 -1
- package/dist/services/budget-evaluator.d.cts +2 -2
- package/dist/services/budget-evaluator.d.cts.map +1 -1
- package/dist/services/budget-evaluator.d.ts +2 -2
- package/dist/services/budget-evaluator.d.ts.map +1 -1
- package/dist/services/budget-evaluator.js +8 -6
- package/dist/services/budget-evaluator.js.map +1 -1
- package/dist/services/budget-resolver.cjs +214 -0
- package/dist/services/budget-resolver.cjs.map +1 -0
- package/dist/services/budget-resolver.d.cts +98 -0
- package/dist/services/budget-resolver.d.cts.map +1 -0
- package/dist/services/budget-resolver.d.ts +98 -0
- package/dist/services/budget-resolver.d.ts.map +1 -0
- package/dist/services/budget-resolver.js +203 -0
- package/dist/services/budget-resolver.js.map +1 -0
- package/dist/services/file-loader.cjs +1 -1
- package/dist/services/file-loader.cjs.map +1 -1
- package/dist/services/file-loader.js +1 -1
- package/dist/services/file-loader.js.map +1 -1
- package/dist/services/reporter-loader.cjs +281 -0
- package/dist/services/reporter-loader.cjs.map +1 -0
- package/dist/services/reporter-loader.d.cts +67 -0
- package/dist/services/reporter-loader.d.cts.map +1 -0
- package/dist/services/reporter-loader.d.ts +67 -0
- package/dist/services/reporter-loader.d.ts.map +1 -0
- package/dist/services/reporter-loader.js +241 -0
- package/dist/services/reporter-loader.js.map +1 -0
- package/dist/types/budgets.d.cts +31 -0
- package/dist/types/budgets.d.cts.map +1 -1
- package/dist/types/budgets.d.ts +31 -0
- package/dist/types/budgets.d.ts.map +1 -1
- package/dist/types/core.cjs.map +1 -1
- package/dist/types/core.d.cts +28 -75
- package/dist/types/core.d.cts.map +1 -1
- package/dist/types/core.d.ts +28 -75
- package/dist/types/core.d.ts.map +1 -1
- package/dist/types/core.js.map +1 -1
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.cts +1 -0
- package/dist/types/index.d.cts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/plugin.cjs +9 -0
- package/dist/types/plugin.cjs.map +1 -0
- package/dist/types/plugin.d.cts +179 -0
- package/dist/types/plugin.d.cts.map +1 -0
- package/dist/types/plugin.d.ts +179 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/plugin.js +8 -0
- package/dist/types/plugin.js.map +1 -0
- package/dist/utils/package.cjs +66 -5
- package/dist/utils/package.cjs.map +1 -1
- package/dist/utils/package.d.cts +6 -0
- package/dist/utils/package.d.cts.map +1 -1
- package/dist/utils/package.d.ts +6 -0
- package/dist/utils/package.d.ts.map +1 -1
- package/dist/utils/package.js +31 -1
- package/dist/utils/package.js.map +1 -1
- package/dist/utils/reporter-utils.cjs +90 -0
- package/dist/utils/reporter-utils.cjs.map +1 -0
- package/dist/utils/reporter-utils.d.cts +42 -0
- package/dist/utils/reporter-utils.d.cts.map +1 -0
- package/dist/utils/reporter-utils.d.ts +42 -0
- package/dist/utils/reporter-utils.d.ts.map +1 -0
- package/dist/utils/reporter-utils.js +83 -0
- package/dist/utils/reporter-utils.js.map +1 -0
- package/package.json +20 -9
- package/src/adapters/types.ts +1 -1
- package/src/cli/commands/run.ts +140 -69
- package/src/cli/index.ts +8 -1
- package/src/{core → config}/benchmark-schema.ts +1 -1
- package/src/config/schema.ts +379 -302
- package/src/constants.ts +2 -0
- package/src/core/engine.ts +74 -69
- package/src/core/output-path-resolver.ts +14 -0
- package/src/errors/index.ts +2 -0
- package/src/errors/reporter.ts +55 -0
- package/src/index.ts +19 -1
- package/src/reporters/json.ts +1 -1
- package/src/services/budget-evaluator.ts +13 -9
- package/src/services/budget-resolver.ts +254 -0
- package/src/services/file-loader.ts +1 -1
- package/src/services/reporter-loader.ts +323 -0
- package/src/types/budgets.ts +38 -0
- package/src/types/core.ts +64 -99
- package/src/types/index.ts +3 -0
- package/src/types/plugin.ts +197 -0
- package/src/utils/package.ts +32 -1
- package/src/utils/reporter-utils.ts +85 -0
- package/dist/core/benchmark-schema.cjs.map +0 -1
- package/dist/core/benchmark-schema.d.cts +0 -139
- package/dist/core/benchmark-schema.d.cts.map +0 -1
- package/dist/core/benchmark-schema.d.ts +0 -139
- package/dist/core/benchmark-schema.d.ts.map +0 -1
- package/dist/core/benchmark-schema.js.map +0 -1
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ModestBench Plugin Types
|
|
3
|
+
*
|
|
4
|
+
* Type definitions for third-party reporter plugins. These types are exported
|
|
5
|
+
* from the main package for use by plugin authors.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { Reporter } from './interfaces.js';
|
|
9
|
+
import type { Logger } from './utility.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Class constructor for reporter plugins
|
|
13
|
+
*
|
|
14
|
+
* Plugin authors can export a default class matching this signature. The class
|
|
15
|
+
* constructor receives options from the config file and a context object with
|
|
16
|
+
* utilities.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
*
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import type { Reporter, ReporterContext } from 'modestbench';
|
|
22
|
+
*
|
|
23
|
+
* interface MyReporterOptions {
|
|
24
|
+
* verbose?: boolean;
|
|
25
|
+
* outputFormat?: 'text' | 'markdown';
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* class MyReporter implements Reporter {
|
|
29
|
+
* constructor(
|
|
30
|
+
* private options: MyReporterOptions,
|
|
31
|
+
* private context: ReporterContext,
|
|
32
|
+
* ) {}
|
|
33
|
+
*
|
|
34
|
+
* onStart(run) {
|
|
35
|
+
* if (this.options.verbose) console.log('Starting');
|
|
36
|
+
* }
|
|
37
|
+
* onEnd(run) {
|
|
38
|
+
* console.log('Done');
|
|
39
|
+
* }
|
|
40
|
+
* onError(error) {
|
|
41
|
+
* console.error(error);
|
|
42
|
+
* }
|
|
43
|
+
* onTaskResult(result) {
|
|
44
|
+
* console.log(
|
|
45
|
+
* `${result.name}: ${this.context.utils.formatDuration(result.mean)}`,
|
|
46
|
+
* );
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* export default MyReporter;
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @typeParam TOptions - The shape of the options object (defaults to
|
|
54
|
+
* Record<string, unknown>)
|
|
55
|
+
*/
|
|
56
|
+
export interface ReporterClass<
|
|
57
|
+
TOptions extends Record<string, unknown> = Record<string, unknown>,
|
|
58
|
+
> {
|
|
59
|
+
new (options?: TOptions, context?: ReporterContext): Reporter;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Context provided to reporter plugins
|
|
64
|
+
*
|
|
65
|
+
* Contains version information and utility functions that plugins can use.
|
|
66
|
+
*/
|
|
67
|
+
export interface ReporterContext {
|
|
68
|
+
/**
|
|
69
|
+
* Logger for reporter output
|
|
70
|
+
*
|
|
71
|
+
* Use this instead of console.log/console.error to ensure output respects the
|
|
72
|
+
* user's verbosity settings and uses the correct output streams.
|
|
73
|
+
*/
|
|
74
|
+
readonly logger: Logger;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Plugin API version
|
|
78
|
+
*
|
|
79
|
+
* Incremented when breaking changes are made to the plugin API. Currently
|
|
80
|
+
* version 1.
|
|
81
|
+
*/
|
|
82
|
+
readonly pluginApiVersion: number;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Utility functions for formatting benchmark data
|
|
86
|
+
*/
|
|
87
|
+
readonly utils: ReporterUtils;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* ModestBench version
|
|
91
|
+
*
|
|
92
|
+
* Plugins can use this to check compatibility.
|
|
93
|
+
*/
|
|
94
|
+
readonly version: string;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Factory function for creating reporter instances
|
|
99
|
+
*
|
|
100
|
+
* Plugin authors can export a default function matching this signature. The
|
|
101
|
+
* function receives options from the config file and a context object with
|
|
102
|
+
* utilities. Use the generic parameter to define the shape of your options.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
*
|
|
106
|
+
* ```typescript
|
|
107
|
+
* import type { ReporterFactory } from 'modestbench';
|
|
108
|
+
*
|
|
109
|
+
* interface MyReporterOptions {
|
|
110
|
+
* verbose?: boolean;
|
|
111
|
+
* outputFormat?: 'text' | 'markdown';
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* const createReporter: ReporterFactory<MyReporterOptions> = (
|
|
115
|
+
* options,
|
|
116
|
+
* context,
|
|
117
|
+
* ) => {
|
|
118
|
+
* return {
|
|
119
|
+
* onStart(run) {
|
|
120
|
+
* if (options.verbose) console.log('Starting');
|
|
121
|
+
* },
|
|
122
|
+
* onEnd(run) {
|
|
123
|
+
* console.log('Done');
|
|
124
|
+
* },
|
|
125
|
+
* onError(error) {
|
|
126
|
+
* console.error(error);
|
|
127
|
+
* },
|
|
128
|
+
* onTaskResult(result) {
|
|
129
|
+
* console.log(
|
|
130
|
+
* `${result.name}: ${context.utils.formatDuration(result.mean)}`,
|
|
131
|
+
* );
|
|
132
|
+
* },
|
|
133
|
+
* };
|
|
134
|
+
* };
|
|
135
|
+
*
|
|
136
|
+
* export default createReporter;
|
|
137
|
+
* ```
|
|
138
|
+
*
|
|
139
|
+
* @typeParam TOptions - The shape of the options object (defaults to
|
|
140
|
+
* Record<string, unknown>)
|
|
141
|
+
*/
|
|
142
|
+
export type ReporterFactory<
|
|
143
|
+
TOptions extends Record<string, unknown> = Record<string, unknown>,
|
|
144
|
+
> = (
|
|
145
|
+
options: TOptions,
|
|
146
|
+
context: ReporterContext,
|
|
147
|
+
) => Promise<Reporter> | Reporter;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Union type representing all valid reporter plugin exports
|
|
151
|
+
*
|
|
152
|
+
* A reporter plugin module can export:
|
|
153
|
+
*
|
|
154
|
+
* - A plain Reporter object (simplest form, no options)
|
|
155
|
+
* - A ReporterClass constructor (instantiated with options)
|
|
156
|
+
* - A ReporterFactory function (most flexible, supports async)
|
|
157
|
+
*/
|
|
158
|
+
export type ReporterPlugin = Reporter | ReporterClass | ReporterFactory;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Utility functions available to reporter plugins
|
|
162
|
+
*
|
|
163
|
+
* These functions help format benchmark data consistently.
|
|
164
|
+
*/
|
|
165
|
+
export interface ReporterUtils {
|
|
166
|
+
/**
|
|
167
|
+
* Format bytes in human-readable format
|
|
168
|
+
*
|
|
169
|
+
* @param bytes - Number of bytes
|
|
170
|
+
* @returns Formatted string (e.g., "1.5 GB", "256 MB")
|
|
171
|
+
*/
|
|
172
|
+
formatBytes(bytes: number): string;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Format duration in human-readable format
|
|
176
|
+
*
|
|
177
|
+
* @param nanoseconds - Duration in nanoseconds
|
|
178
|
+
* @returns Formatted string (e.g., "1.23ms", "456.78μs")
|
|
179
|
+
*/
|
|
180
|
+
formatDuration(nanoseconds: number): string;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Format operations per second
|
|
184
|
+
*
|
|
185
|
+
* @param opsPerSecond - Operations per second
|
|
186
|
+
* @returns Formatted string (e.g., "1.2M ops/sec", "456K ops/sec")
|
|
187
|
+
*/
|
|
188
|
+
formatOpsPerSecond(opsPerSecond: number): string;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Format percentage value
|
|
192
|
+
*
|
|
193
|
+
* @param value - Percentage value
|
|
194
|
+
* @returns Formatted string (e.g., "12.34%")
|
|
195
|
+
*/
|
|
196
|
+
formatPercentage(value: number): string;
|
|
197
|
+
}
|
package/src/utils/package.ts
CHANGED
|
@@ -6,8 +6,39 @@
|
|
|
6
6
|
* @packageDocumentation
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { readFileSync } from 'node:fs';
|
|
9
10
|
import { readFile } from 'node:fs/promises';
|
|
10
|
-
import path from 'node:path';
|
|
11
|
+
import path, { dirname, join } from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Cached package version, loaded at module initialization
|
|
16
|
+
*
|
|
17
|
+
* NOTE: This relies on package.json being at the same relative path from both
|
|
18
|
+
* src/ and dist/ directories (../../package.json). If the build output
|
|
19
|
+
* structure changes, this will break.
|
|
20
|
+
*/
|
|
21
|
+
const cachedPackageVersion = (() => {
|
|
22
|
+
try {
|
|
23
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
24
|
+
const pkgPath = join(__dirname, '..', '..', 'package.json');
|
|
25
|
+
const pkgContent = readFileSync(pkgPath, 'utf8');
|
|
26
|
+
const pkg = JSON.parse(pkgContent) as { version: string };
|
|
27
|
+
return pkg.version;
|
|
28
|
+
} catch {
|
|
29
|
+
// Fallback if package.json cannot be read (shouldn't happen in normal use)
|
|
30
|
+
return 'unknown';
|
|
31
|
+
}
|
|
32
|
+
})();
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Get the ModestBench package version
|
|
36
|
+
*
|
|
37
|
+
* @returns The version string from package.json
|
|
38
|
+
*/
|
|
39
|
+
export const getPackageVersion = (): string => {
|
|
40
|
+
return cachedPackageVersion;
|
|
41
|
+
};
|
|
11
42
|
|
|
12
43
|
/**
|
|
13
44
|
* Find the nearest package.json and return its directory
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ModestBench Reporter Utilities
|
|
3
|
+
*
|
|
4
|
+
* Formatting functions for benchmark data, exported for use by third-party
|
|
5
|
+
* reporter plugins.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ReporterUtils } from '../types/plugin.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Format bytes in human-readable format
|
|
12
|
+
*
|
|
13
|
+
* @param bytes - Number of bytes
|
|
14
|
+
* @returns Formatted string (e.g., "1.5 GB", "256 MB", "1.2 KB")
|
|
15
|
+
*/
|
|
16
|
+
export const formatBytes = (bytes: number): string => {
|
|
17
|
+
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
18
|
+
let size = bytes;
|
|
19
|
+
let unitIndex = 0;
|
|
20
|
+
|
|
21
|
+
while (size >= 1024 && unitIndex < units.length - 1) {
|
|
22
|
+
size /= 1024;
|
|
23
|
+
unitIndex++;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return `${size.toFixed(1)} ${units[unitIndex]}`;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Format duration in human-readable format
|
|
31
|
+
*
|
|
32
|
+
* @param nanoseconds - Duration in nanoseconds
|
|
33
|
+
* @returns Formatted string (e.g., "1.23ms", "456.78μs", "789.00ns")
|
|
34
|
+
*/
|
|
35
|
+
export const formatDuration = (nanoseconds: number): string => {
|
|
36
|
+
if (nanoseconds < 1000) {
|
|
37
|
+
return `${nanoseconds.toFixed(2)}ns`;
|
|
38
|
+
} else if (nanoseconds < 1_000_000) {
|
|
39
|
+
return `${(nanoseconds / 1000).toFixed(2)}μs`;
|
|
40
|
+
} else if (nanoseconds < 1_000_000_000) {
|
|
41
|
+
return `${(nanoseconds / 1_000_000).toFixed(2)}ms`;
|
|
42
|
+
} else {
|
|
43
|
+
return `${(nanoseconds / 1_000_000_000).toFixed(2)}s`;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Format operations per second in human-readable format
|
|
49
|
+
*
|
|
50
|
+
* @param opsPerSecond - Operations per second
|
|
51
|
+
* @returns Formatted string (e.g., "1.2M ops/sec", "456K ops/sec")
|
|
52
|
+
*/
|
|
53
|
+
export const formatOpsPerSecond = (opsPerSecond: number): string => {
|
|
54
|
+
if (opsPerSecond < 1000) {
|
|
55
|
+
return `${opsPerSecond.toFixed(2)} ops/sec`;
|
|
56
|
+
} else if (opsPerSecond < 1_000_000) {
|
|
57
|
+
return `${(opsPerSecond / 1000).toFixed(2)}K ops/sec`;
|
|
58
|
+
} else if (opsPerSecond < 1_000_000_000) {
|
|
59
|
+
return `${(opsPerSecond / 1_000_000).toFixed(2)}M ops/sec`;
|
|
60
|
+
} else {
|
|
61
|
+
return `${(opsPerSecond / 1_000_000_000).toFixed(2)}B ops/sec`;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Format percentage value
|
|
67
|
+
*
|
|
68
|
+
* @param value - Percentage value (e.g., 12.345 for 12.345%)
|
|
69
|
+
* @returns Formatted string (e.g., "12.35%")
|
|
70
|
+
*/
|
|
71
|
+
export const formatPercentage = (value: number): string => {
|
|
72
|
+
return `${value.toFixed(2)}%`;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Reporter utilities object implementing the ReporterUtils interface
|
|
77
|
+
*
|
|
78
|
+
* This object is provided to reporter plugins via the ReporterContext.
|
|
79
|
+
*/
|
|
80
|
+
export const reporterUtils: ReporterUtils = {
|
|
81
|
+
formatBytes,
|
|
82
|
+
formatDuration,
|
|
83
|
+
formatOpsPerSecond,
|
|
84
|
+
formatPercentage,
|
|
85
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"benchmark-schema.js","sourceRoot":"","sources":["../../src/core/benchmark-schema.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,6BAAwB;AAIxB,oDAAqE;AAErE;;GAEG;AACH,MAAM,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAChC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,UAAU,EACtC,EAAE,OAAO,EAAE,qBAAqB,EAAE,CACnC,CAAC;AAEF;;GAEG;AACH,MAAM,yBAAyB,GAAG,OAAC,CAAC,MAAM,CAAC;IACzC,MAAM,EAAE,0CAA8B;SACnC,QAAQ,EAAE;SACV,QAAQ,CAAC,uCAAuC,CAAC;IACpD,EAAE,EAAE,iBAAiB,CAAC,QAAQ,CAAC,2BAA2B,CAAC;IAC3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O,EAAE;gBACP,UAAU,EAAE,MAAM,CAAC,WAAW,CAC5B,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAC1D;aACF;SACF;QACD,IAAI,EAAE,SAAiC;KACxC,CAAC,CAAC;CACN,CAAC;KACD,QAAQ,CACP,gFAAgF,CACjF,CAAC"}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ModestBench Benchmark File Schema
|
|
3
|
-
*
|
|
4
|
-
* Zod schemas for validating and parsing benchmark file structure. Supports
|
|
5
|
-
* both traditional suite-based format and simplified flat task definitions.
|
|
6
|
-
*
|
|
7
|
-
* Types are derived from schemas using z.infer (output) and z.input (input).
|
|
8
|
-
*/
|
|
9
|
-
import { z } from 'zod';
|
|
10
|
-
import type { ModestBenchConfig } from "../types/core.cjs";
|
|
11
|
-
/**
|
|
12
|
-
* Zod schema for a benchmark task - accepts either:
|
|
13
|
-
*
|
|
14
|
-
* 1. A full task object with fn, config, metadata, tags
|
|
15
|
-
* 2. A function directly (shorthand syntax)
|
|
16
|
-
*
|
|
17
|
-
* Input: function OR object Output: always normalized to object with fn
|
|
18
|
-
* property
|
|
19
|
-
*/
|
|
20
|
-
declare const benchmarkTaskSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodObject<{
|
|
21
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
22
|
-
fn: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
23
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
24
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
|
-
}, z.core.$strip>, z.ZodPipe<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>, z.ZodTransform<{
|
|
26
|
-
fn: (...args: any[]) => unknown;
|
|
27
|
-
}, (...args: any[]) => unknown>>]>, z.ZodObject<{
|
|
28
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
29
|
-
fn: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
30
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
31
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
32
|
-
}, z.core.$strip>>;
|
|
33
|
-
/**
|
|
34
|
-
* Zod schema for validating benchmark suite structure
|
|
35
|
-
*/
|
|
36
|
-
declare const benchmarkSuiteSchema: z.ZodObject<{
|
|
37
|
-
benchmarks: z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodUnion<readonly [z.ZodObject<{
|
|
38
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
39
|
-
fn: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
40
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
41
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
42
|
-
}, z.core.$strip>, z.ZodPipe<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>, z.ZodTransform<{
|
|
43
|
-
fn: (...args: any[]) => unknown;
|
|
44
|
-
}, (...args: any[]) => unknown>>]>, z.ZodObject<{
|
|
45
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
46
|
-
fn: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
47
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
48
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
49
|
-
}, z.core.$strip>>>;
|
|
50
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
51
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
52
|
-
setup: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
53
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
54
|
-
teardown: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
55
|
-
}, z.core.$strip>;
|
|
56
|
-
/**
|
|
57
|
-
* Zod schema for validating benchmark file structure.
|
|
58
|
-
*
|
|
59
|
-
* Supports two formats:
|
|
60
|
-
*
|
|
61
|
-
* 1. Suite format (supports config/metadata/tags): { suites: { 'Suite Name': {
|
|
62
|
-
* benchmarks: {...} } }, config: {...} }
|
|
63
|
-
* 2. Flat format (simple, tasks only - no config/metadata/tags): { 'task name': ()
|
|
64
|
-
* => {...} }
|
|
65
|
-
*
|
|
66
|
-
* The flat format is automatically transformed to suite format with a default
|
|
67
|
-
* suite.
|
|
68
|
-
*
|
|
69
|
-
* Input: flat Record<string, function> OR suite object Output: always
|
|
70
|
-
* normalized to suite format
|
|
71
|
-
*/
|
|
72
|
-
export declare const benchmarkFileSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
73
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
74
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
75
|
-
suites: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
76
|
-
benchmarks: z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodUnion<readonly [z.ZodObject<{
|
|
77
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
78
|
-
fn: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
79
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
80
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
81
|
-
}, z.core.$strip>, z.ZodPipe<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>, z.ZodTransform<{
|
|
82
|
-
fn: (...args: any[]) => unknown;
|
|
83
|
-
}, (...args: any[]) => unknown>>]>, z.ZodObject<{
|
|
84
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
85
|
-
fn: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
86
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
87
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
88
|
-
}, z.core.$strip>>>;
|
|
89
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
90
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
91
|
-
setup: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
92
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
93
|
-
teardown: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
94
|
-
}, z.core.$strip>>;
|
|
95
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
96
|
-
}, z.core.$strip>, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>, z.ZodTransform<{
|
|
97
|
-
config: Partial<ModestBenchConfig> | undefined;
|
|
98
|
-
metadata: Record<string, unknown> | undefined;
|
|
99
|
-
suites: {
|
|
100
|
-
default: {
|
|
101
|
-
benchmarks: {
|
|
102
|
-
[k: string]: {
|
|
103
|
-
fn: (...args: any[]) => unknown;
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
tags: string[] | undefined;
|
|
109
|
-
}, Record<string, (...args: any[]) => unknown>>>]>;
|
|
110
|
-
/**
|
|
111
|
-
* Benchmark file definition (normalized) - internal representation Always in
|
|
112
|
-
* suite format
|
|
113
|
-
*/
|
|
114
|
-
export type BenchmarkDefinition = z.infer<typeof benchmarkFileSchema>;
|
|
115
|
-
/**
|
|
116
|
-
* Benchmark file definition (input) - what users write Can be either flat
|
|
117
|
-
* format (Record<string, function>) or suite format
|
|
118
|
-
*/
|
|
119
|
-
export type BenchmarkDefinitionInput = z.input<typeof benchmarkFileSchema>;
|
|
120
|
-
/**
|
|
121
|
-
* Benchmark suite (normalized) - internal representation
|
|
122
|
-
*/
|
|
123
|
-
export type BenchmarkSuite = z.infer<typeof benchmarkSuiteSchema>;
|
|
124
|
-
/**
|
|
125
|
-
* Benchmark suite (input) - what users write
|
|
126
|
-
*/
|
|
127
|
-
export type BenchmarkSuiteInput = z.input<typeof benchmarkSuiteSchema>;
|
|
128
|
-
/**
|
|
129
|
-
* Benchmark task (normalized) - internal representation Always an object with
|
|
130
|
-
* fn property
|
|
131
|
-
*/
|
|
132
|
-
export type BenchmarkTask = z.infer<typeof benchmarkTaskSchema>;
|
|
133
|
-
/**
|
|
134
|
-
* Benchmark task (input) - what users write Can be either a function or an
|
|
135
|
-
* object with fn property
|
|
136
|
-
*/
|
|
137
|
-
export type BenchmarkTaskInput = z.input<typeof benchmarkTaskSchema>;
|
|
138
|
-
export {};
|
|
139
|
-
//# sourceMappingURL=benchmark-schema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"benchmark-schema.d.ts","sourceRoot":"","sources":["../../src/core/benchmark-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAAyB;AA8B1D;;;;;;;;GAQG;AACH,QAAA,MAAM,mBAAmB;;8BAhCoB,GAAG,EAAE,KAAK,OAAO,YAAjB,GAAG,EAAE,KAAK,OAAO;;;mDAAjB,GAAG,EAAE,KAAK,OAAO,YAAjB,GAAG,EAAE,KAAK,OAAO;kBAAjB,GAAG,EAAE,KAAK,OAAO;aAAjB,GAAG,EAAE,KAAK,OAAO;;8BAAjB,GAAG,EAAE,KAAK,OAAO,YAAjB,GAAG,EAAE,KAAK,OAAO;;;kBAsCQ,CAAC;AAEvE;;GAEG;AACH,QAAA,MAAM,oBAAoB;;;kCA3CmB,GAAG,EAAE,KAAK,OAAO,YAAjB,GAAG,EAAE,KAAK,OAAO;;;uDAAjB,GAAG,EAAE,KAAK,OAAO,YAAjB,GAAG,EAAE,KAAK,OAAO;sBAAjB,GAAG,EAAE,KAAK,OAAO;iBAAjB,GAAG,EAAE,KAAK,OAAO;;kCAAjB,GAAG,EAAE,KAAK,OAAO,YAAjB,GAAG,EAAE,KAAK,OAAO;;;;;;+CAAjB,GAAG,EAAE,KAAK,OAAO,YAAjB,GAAG,EAAE,KAAK,OAAO;;kDAAjB,GAAG,EAAE,KAAK,OAAO,YAAjB,GAAG,EAAE,KAAK,OAAO;iBAkEJ,CAAC;AAE3D;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,mBAAmB;;;;;;sCApFa,GAAG,EAAE,KAAK,OAAO,YAAjB,GAAG,EAAE,KAAK,OAAO;;;2DAAjB,G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|
2
|
-
* ModestBench Benchmark File Schema
|
|
3
|
-
*
|
|
4
|
-
* Zod schemas for validating and parsing benchmark file structure. Supports
|
|
5
|
-
* both traditional suite-based format and simplified flat task definitions.
|
|
6
|
-
*
|
|
7
|
-
* Types are derived from schemas using z.infer (output) and z.input (input).
|
|
8
|
-
*/
|
|
9
|
-
import { z } from 'zod';
|
|
10
|
-
import type { ModestBenchConfig } from "../types/core.js";
|
|
11
|
-
/**
|
|
12
|
-
* Zod schema for a benchmark task - accepts either:
|
|
13
|
-
*
|
|
14
|
-
* 1. A full task object with fn, config, metadata, tags
|
|
15
|
-
* 2. A function directly (shorthand syntax)
|
|
16
|
-
*
|
|
17
|
-
* Input: function OR object Output: always normalized to object with fn
|
|
18
|
-
* property
|
|
19
|
-
*/
|
|
20
|
-
declare const benchmarkTaskSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodObject<{
|
|
21
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
22
|
-
fn: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
23
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
24
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
25
|
-
}, z.core.$strip>, z.ZodPipe<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>, z.ZodTransform<{
|
|
26
|
-
fn: (...args: any[]) => unknown;
|
|
27
|
-
}, (...args: any[]) => unknown>>]>, z.ZodObject<{
|
|
28
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
29
|
-
fn: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
30
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
31
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
32
|
-
}, z.core.$strip>>;
|
|
33
|
-
/**
|
|
34
|
-
* Zod schema for validating benchmark suite structure
|
|
35
|
-
*/
|
|
36
|
-
declare const benchmarkSuiteSchema: z.ZodObject<{
|
|
37
|
-
benchmarks: z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodUnion<readonly [z.ZodObject<{
|
|
38
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
39
|
-
fn: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
40
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
41
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
42
|
-
}, z.core.$strip>, z.ZodPipe<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>, z.ZodTransform<{
|
|
43
|
-
fn: (...args: any[]) => unknown;
|
|
44
|
-
}, (...args: any[]) => unknown>>]>, z.ZodObject<{
|
|
45
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
46
|
-
fn: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
47
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
48
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
49
|
-
}, z.core.$strip>>>;
|
|
50
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
51
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
52
|
-
setup: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
53
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
54
|
-
teardown: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
55
|
-
}, z.core.$strip>;
|
|
56
|
-
/**
|
|
57
|
-
* Zod schema for validating benchmark file structure.
|
|
58
|
-
*
|
|
59
|
-
* Supports two formats:
|
|
60
|
-
*
|
|
61
|
-
* 1. Suite format (supports config/metadata/tags): { suites: { 'Suite Name': {
|
|
62
|
-
* benchmarks: {...} } }, config: {...} }
|
|
63
|
-
* 2. Flat format (simple, tasks only - no config/metadata/tags): { 'task name': ()
|
|
64
|
-
* => {...} }
|
|
65
|
-
*
|
|
66
|
-
* The flat format is automatically transformed to suite format with a default
|
|
67
|
-
* suite.
|
|
68
|
-
*
|
|
69
|
-
* Input: flat Record<string, function> OR suite object Output: always
|
|
70
|
-
* normalized to suite format
|
|
71
|
-
*/
|
|
72
|
-
export declare const benchmarkFileSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
73
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
74
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
75
|
-
suites: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
76
|
-
benchmarks: z.ZodRecord<z.ZodString, z.ZodPipe<z.ZodUnion<readonly [z.ZodObject<{
|
|
77
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
78
|
-
fn: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
79
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
80
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
81
|
-
}, z.core.$strip>, z.ZodPipe<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>, z.ZodTransform<{
|
|
82
|
-
fn: (...args: any[]) => unknown;
|
|
83
|
-
}, (...args: any[]) => unknown>>]>, z.ZodObject<{
|
|
84
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
85
|
-
fn: z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>;
|
|
86
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
87
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
88
|
-
}, z.core.$strip>>>;
|
|
89
|
-
config: z.ZodOptional<z.ZodType<Partial<ModestBenchConfig>, unknown, z.core.$ZodTypeInternals<Partial<ModestBenchConfig>, unknown>>>;
|
|
90
|
-
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
91
|
-
setup: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
92
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
93
|
-
teardown: z.ZodOptional<z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>;
|
|
94
|
-
}, z.core.$strip>>;
|
|
95
|
-
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
96
|
-
}, z.core.$strip>, z.ZodPipe<z.ZodRecord<z.ZodString, z.ZodCustom<(...args: any[]) => unknown, (...args: any[]) => unknown>>, z.ZodTransform<{
|
|
97
|
-
config: Partial<ModestBenchConfig> | undefined;
|
|
98
|
-
metadata: Record<string, unknown> | undefined;
|
|
99
|
-
suites: {
|
|
100
|
-
default: {
|
|
101
|
-
benchmarks: {
|
|
102
|
-
[k: string]: {
|
|
103
|
-
fn: (...args: any[]) => unknown;
|
|
104
|
-
};
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
};
|
|
108
|
-
tags: string[] | undefined;
|
|
109
|
-
}, Record<string, (...args: any[]) => unknown>>>]>;
|
|
110
|
-
/**
|
|
111
|
-
* Benchmark file definition (normalized) - internal representation Always in
|
|
112
|
-
* suite format
|
|
113
|
-
*/
|
|
114
|
-
export type BenchmarkDefinition = z.infer<typeof benchmarkFileSchema>;
|
|
115
|
-
/**
|
|
116
|
-
* Benchmark file definition (input) - what users write Can be either flat
|
|
117
|
-
* format (Record<string, function>) or suite format
|
|
118
|
-
*/
|
|
119
|
-
export type BenchmarkDefinitionInput = z.input<typeof benchmarkFileSchema>;
|
|
120
|
-
/**
|
|
121
|
-
* Benchmark suite (normalized) - internal representation
|
|
122
|
-
*/
|
|
123
|
-
export type BenchmarkSuite = z.infer<typeof benchmarkSuiteSchema>;
|
|
124
|
-
/**
|
|
125
|
-
* Benchmark suite (input) - what users write
|
|
126
|
-
*/
|
|
127
|
-
export type BenchmarkSuiteInput = z.input<typeof benchmarkSuiteSchema>;
|
|
128
|
-
/**
|
|
129
|
-
* Benchmark task (normalized) - internal representation Always an object with
|
|
130
|
-
* fn property
|
|
131
|
-
*/
|
|
132
|
-
export type BenchmarkTask = z.infer<typeof benchmarkTaskSchema>;
|
|
133
|
-
/**
|
|
134
|
-
* Benchmark task (input) - what users write Can be either a function or an
|
|
135
|
-
* object with fn property
|
|
136
|
-
*/
|
|
137
|
-
export type BenchmarkTaskInput = z.input<typeof benchmarkTaskSchema>;
|
|
138
|
-
export {};
|
|
139
|
-
//# sourceMappingURL=benchmark-schema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"benchmark-schema.d.ts","sourceRoot":"","sources":["../../src/core/benchmark-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,iBAAiB,EAAE,yBAAyB;AA8B1D;;;;;;;;GAQG;AACH,QAAA,MAAM,mBAAmB;;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