modestbench 0.0.1
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 +45 -0
- package/LICENSE.md +55 -0
- package/README.md +699 -0
- package/dist/bootstrap.cjs +37 -0
- package/dist/bootstrap.cjs.map +1 -0
- package/dist/bootstrap.d.cts +17 -0
- package/dist/bootstrap.d.cts.map +1 -0
- package/dist/bootstrap.d.ts +17 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/bootstrap.js +33 -0
- package/dist/bootstrap.js.map +1 -0
- package/dist/cli/commands/history.cjs +459 -0
- package/dist/cli/commands/history.cjs.map +1 -0
- package/dist/cli/commands/history.d.cts +34 -0
- package/dist/cli/commands/history.d.cts.map +1 -0
- package/dist/cli/commands/history.d.ts +34 -0
- package/dist/cli/commands/history.d.ts.map +1 -0
- package/dist/cli/commands/history.js +422 -0
- package/dist/cli/commands/history.js.map +1 -0
- package/dist/cli/commands/init.cjs +566 -0
- package/dist/cli/commands/init.cjs.map +1 -0
- package/dist/cli/commands/init.d.cts +26 -0
- package/dist/cli/commands/init.d.cts.map +1 -0
- package/dist/cli/commands/init.d.ts +26 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +562 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/run.cjs +285 -0
- package/dist/cli/commands/run.cjs.map +1 -0
- package/dist/cli/commands/run.d.cts +37 -0
- package/dist/cli/commands/run.d.cts.map +1 -0
- package/dist/cli/commands/run.d.ts +37 -0
- package/dist/cli/commands/run.d.ts.map +1 -0
- package/dist/cli/commands/run.js +248 -0
- package/dist/cli/commands/run.js.map +1 -0
- package/dist/cli/index.cjs +523 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +58 -0
- package/dist/cli/index.d.cts.map +1 -0
- package/dist/cli/index.d.ts +58 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +515 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/config/manager.cjs +370 -0
- package/dist/config/manager.cjs.map +1 -0
- package/dist/config/manager.d.cts +46 -0
- package/dist/config/manager.d.cts.map +1 -0
- package/dist/config/manager.d.ts +46 -0
- package/dist/config/manager.d.ts.map +1 -0
- package/dist/config/manager.js +333 -0
- package/dist/config/manager.js.map +1 -0
- package/dist/config/schema.cjs +182 -0
- package/dist/config/schema.cjs.map +1 -0
- package/dist/config/schema.d.cts +51 -0
- package/dist/config/schema.d.cts.map +1 -0
- package/dist/config/schema.d.ts +51 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +145 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/constants.cjs +22 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +10 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.ts +10 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +19 -0
- package/dist/constants.js.map +1 -0
- package/dist/core/benchmark-schema.cjs +135 -0
- package/dist/core/benchmark-schema.cjs.map +1 -0
- package/dist/core/benchmark-schema.d.cts +139 -0
- package/dist/core/benchmark-schema.d.cts.map +1 -0
- package/dist/core/benchmark-schema.d.ts +139 -0
- package/dist/core/benchmark-schema.d.ts.map +1 -0
- package/dist/core/benchmark-schema.js +132 -0
- package/dist/core/benchmark-schema.js.map +1 -0
- package/dist/core/engine.cjs +669 -0
- package/dist/core/engine.cjs.map +1 -0
- package/dist/core/engine.d.cts +128 -0
- package/dist/core/engine.d.cts.map +1 -0
- package/dist/core/engine.d.ts +128 -0
- package/dist/core/engine.d.ts.map +1 -0
- package/dist/core/engine.js +632 -0
- package/dist/core/engine.js.map +1 -0
- package/dist/core/engines/accurate-engine.cjs +292 -0
- package/dist/core/engines/accurate-engine.cjs.map +1 -0
- package/dist/core/engines/accurate-engine.d.cts +63 -0
- package/dist/core/engines/accurate-engine.d.cts.map +1 -0
- package/dist/core/engines/accurate-engine.d.ts +63 -0
- package/dist/core/engines/accurate-engine.d.ts.map +1 -0
- package/dist/core/engines/accurate-engine.js +288 -0
- package/dist/core/engines/accurate-engine.js.map +1 -0
- package/dist/core/engines/index.cjs +21 -0
- package/dist/core/engines/index.cjs.map +1 -0
- package/dist/core/engines/index.d.cts +16 -0
- package/dist/core/engines/index.d.cts.map +1 -0
- package/dist/core/engines/index.d.ts +16 -0
- package/dist/core/engines/index.d.ts.map +1 -0
- package/dist/core/engines/index.js +16 -0
- package/dist/core/engines/index.js.map +1 -0
- package/dist/core/engines/tinybench-engine.cjs +286 -0
- package/dist/core/engines/tinybench-engine.cjs.map +1 -0
- package/dist/core/engines/tinybench-engine.d.cts +18 -0
- package/dist/core/engines/tinybench-engine.d.cts.map +1 -0
- package/dist/core/engines/tinybench-engine.d.ts +18 -0
- package/dist/core/engines/tinybench-engine.d.ts.map +1 -0
- package/dist/core/engines/tinybench-engine.js +282 -0
- package/dist/core/engines/tinybench-engine.js.map +1 -0
- package/dist/core/error-manager.cjs +303 -0
- package/dist/core/error-manager.cjs.map +1 -0
- package/dist/core/error-manager.d.cts +77 -0
- package/dist/core/error-manager.d.cts.map +1 -0
- package/dist/core/error-manager.d.ts +77 -0
- package/dist/core/error-manager.d.ts.map +1 -0
- package/dist/core/error-manager.js +299 -0
- package/dist/core/error-manager.js.map +1 -0
- package/dist/core/loader.cjs +287 -0
- package/dist/core/loader.cjs.map +1 -0
- package/dist/core/loader.d.cts +55 -0
- package/dist/core/loader.d.cts.map +1 -0
- package/dist/core/loader.d.ts +55 -0
- package/dist/core/loader.d.ts.map +1 -0
- package/dist/core/loader.js +250 -0
- package/dist/core/loader.js.map +1 -0
- package/dist/core/stats-utils.cjs +99 -0
- package/dist/core/stats-utils.cjs.map +1 -0
- package/dist/core/stats-utils.d.cts +50 -0
- package/dist/core/stats-utils.d.cts.map +1 -0
- package/dist/core/stats-utils.d.ts +50 -0
- package/dist/core/stats-utils.d.ts.map +1 -0
- package/dist/core/stats-utils.js +94 -0
- package/dist/core/stats-utils.js.map +1 -0
- package/dist/index.cjs +64 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +22 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +30 -0
- package/dist/index.js.map +1 -0
- package/dist/progress/manager.cjs +325 -0
- package/dist/progress/manager.cjs.map +1 -0
- package/dist/progress/manager.d.cts +125 -0
- package/dist/progress/manager.d.cts.map +1 -0
- package/dist/progress/manager.d.ts +125 -0
- package/dist/progress/manager.d.ts.map +1 -0
- package/dist/progress/manager.js +321 -0
- package/dist/progress/manager.js.map +1 -0
- package/dist/reporters/csv.cjs +250 -0
- package/dist/reporters/csv.cjs.map +1 -0
- package/dist/reporters/csv.d.cts +92 -0
- package/dist/reporters/csv.d.cts.map +1 -0
- package/dist/reporters/csv.d.ts +92 -0
- package/dist/reporters/csv.d.ts.map +1 -0
- package/dist/reporters/csv.js +246 -0
- package/dist/reporters/csv.js.map +1 -0
- package/dist/reporters/human.cjs +516 -0
- package/dist/reporters/human.cjs.map +1 -0
- package/dist/reporters/human.d.cts +86 -0
- package/dist/reporters/human.d.cts.map +1 -0
- package/dist/reporters/human.d.ts +86 -0
- package/dist/reporters/human.d.ts.map +1 -0
- package/dist/reporters/human.js +509 -0
- package/dist/reporters/human.js.map +1 -0
- package/dist/reporters/index.cjs +17 -0
- package/dist/reporters/index.cjs.map +1 -0
- package/dist/reporters/index.d.cts +10 -0
- package/dist/reporters/index.d.cts.map +1 -0
- package/dist/reporters/index.d.ts +10 -0
- package/dist/reporters/index.d.ts.map +1 -0
- package/dist/reporters/index.js +10 -0
- package/dist/reporters/index.js.map +1 -0
- package/dist/reporters/json.cjs +215 -0
- package/dist/reporters/json.cjs.map +1 -0
- package/dist/reporters/json.d.cts +79 -0
- package/dist/reporters/json.d.cts.map +1 -0
- package/dist/reporters/json.d.ts +79 -0
- package/dist/reporters/json.d.ts.map +1 -0
- package/dist/reporters/json.js +211 -0
- package/dist/reporters/json.js.map +1 -0
- package/dist/reporters/registry.cjs +255 -0
- package/dist/reporters/registry.cjs.map +1 -0
- package/dist/reporters/registry.d.cts +155 -0
- package/dist/reporters/registry.d.cts.map +1 -0
- package/dist/reporters/registry.d.ts +155 -0
- package/dist/reporters/registry.d.ts.map +1 -0
- package/dist/reporters/registry.js +249 -0
- package/dist/reporters/registry.js.map +1 -0
- package/dist/reporters/simple.cjs +328 -0
- package/dist/reporters/simple.cjs.map +1 -0
- package/dist/reporters/simple.d.cts +51 -0
- package/dist/reporters/simple.d.cts.map +1 -0
- package/dist/reporters/simple.d.ts +51 -0
- package/dist/reporters/simple.d.ts.map +1 -0
- package/dist/reporters/simple.js +321 -0
- package/dist/reporters/simple.js.map +1 -0
- package/dist/schema/modestbench-config.schema.json +162 -0
- package/dist/storage/history.cjs +456 -0
- package/dist/storage/history.cjs.map +1 -0
- package/dist/storage/history.d.cts +99 -0
- package/dist/storage/history.d.cts.map +1 -0
- package/dist/storage/history.d.ts +99 -0
- package/dist/storage/history.d.ts.map +1 -0
- package/dist/storage/history.js +452 -0
- package/dist/storage/history.js.map +1 -0
- package/dist/types/cli.cjs +21 -0
- package/dist/types/cli.cjs.map +1 -0
- package/dist/types/cli.d.cts +296 -0
- package/dist/types/cli.d.cts.map +1 -0
- package/dist/types/cli.d.ts +296 -0
- package/dist/types/cli.d.ts.map +1 -0
- package/dist/types/cli.js +18 -0
- package/dist/types/cli.js.map +1 -0
- package/dist/types/core.cjs +14 -0
- package/dist/types/core.cjs.map +1 -0
- package/dist/types/core.d.cts +380 -0
- package/dist/types/core.d.cts.map +1 -0
- package/dist/types/core.d.ts +380 -0
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +13 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/index.cjs +27 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +11 -0
- package/dist/types/index.d.cts.map +1 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +11 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/interfaces.cjs +10 -0
- package/dist/types/interfaces.cjs.map +1 -0
- package/dist/types/interfaces.d.cts +381 -0
- package/dist/types/interfaces.d.cts.map +1 -0
- package/dist/types/interfaces.d.ts +381 -0
- package/dist/types/interfaces.d.ts.map +1 -0
- package/dist/types/interfaces.js +9 -0
- package/dist/types/interfaces.js.map +1 -0
- package/dist/types/utility.cjs +92 -0
- package/dist/types/utility.cjs.map +1 -0
- package/dist/types/utility.d.cts +330 -0
- package/dist/types/utility.d.cts.map +1 -0
- package/dist/types/utility.d.ts +330 -0
- package/dist/types/utility.d.ts.map +1 -0
- package/dist/types/utility.js +78 -0
- package/dist/types/utility.js.map +1 -0
- package/package.json +211 -0
- package/src/bootstrap.ts +35 -0
- package/src/cli/commands/history.ts +569 -0
- package/src/cli/commands/init.ts +658 -0
- package/src/cli/commands/run.ts +346 -0
- package/src/cli/index.ts +642 -0
- package/src/config/manager.ts +387 -0
- package/src/config/schema.ts +188 -0
- package/src/constants.ts +21 -0
- package/src/core/benchmark-schema.ts +185 -0
- package/src/core/engine.ts +888 -0
- package/src/core/engines/accurate-engine.ts +408 -0
- package/src/core/engines/index.ts +16 -0
- package/src/core/engines/tinybench-engine.ts +335 -0
- package/src/core/error-manager.ts +372 -0
- package/src/core/loader.ts +324 -0
- package/src/core/stats-utils.ts +135 -0
- package/src/index.ts +46 -0
- package/src/progress/manager.ts +415 -0
- package/src/reporters/csv.ts +368 -0
- package/src/reporters/human.ts +707 -0
- package/src/reporters/index.ts +10 -0
- package/src/reporters/json.ts +302 -0
- package/src/reporters/registry.ts +349 -0
- package/src/reporters/simple.ts +459 -0
- package/src/storage/history.ts +600 -0
- package/src/types/cli.ts +312 -0
- package/src/types/core.ts +414 -0
- package/src/types/index.ts +18 -0
- package/src/types/interfaces.ts +451 -0
- package/src/types/utility.ts +446 -0
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
|
|
12
|
+
import type { ModestBenchConfig } from '../types/core.js';
|
|
13
|
+
|
|
14
|
+
import { partialModestBenchConfigSchema } from '../config/schema.js';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Schema for benchmark functions
|
|
18
|
+
*/
|
|
19
|
+
const benchmarkFnSchema = z.custom<(...args: any[]) => unknown>(
|
|
20
|
+
(value) => typeof value === 'function',
|
|
21
|
+
{ message: 'Expected a function' },
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Zod schema for the full benchmark task object structure (normalized output)
|
|
26
|
+
*/
|
|
27
|
+
const benchmarkTaskObjectSchema = z.object({
|
|
28
|
+
config: partialModestBenchConfigSchema
|
|
29
|
+
.optional()
|
|
30
|
+
.describe('Task-specific configuration overrides'),
|
|
31
|
+
fn: benchmarkFnSchema.describe('The function to benchmark'),
|
|
32
|
+
metadata: z
|
|
33
|
+
.record(z.string(), z.unknown())
|
|
34
|
+
.optional()
|
|
35
|
+
.describe('Custom metadata associated with the task'),
|
|
36
|
+
tags: z
|
|
37
|
+
.array(z.string())
|
|
38
|
+
.optional()
|
|
39
|
+
.describe('Tags for filtering and grouping tasks'),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Zod schema for a benchmark task - accepts either:
|
|
44
|
+
*
|
|
45
|
+
* 1. A full task object with fn, config, metadata, tags
|
|
46
|
+
* 2. A function directly (shorthand syntax)
|
|
47
|
+
*
|
|
48
|
+
* Input: function OR object Output: always normalized to object with fn
|
|
49
|
+
* property
|
|
50
|
+
*/
|
|
51
|
+
const benchmarkTaskSchema = z
|
|
52
|
+
.union([
|
|
53
|
+
benchmarkTaskObjectSchema,
|
|
54
|
+
benchmarkFnSchema.transform((fn) => ({ fn })),
|
|
55
|
+
])
|
|
56
|
+
.pipe(benchmarkTaskObjectSchema)
|
|
57
|
+
.describe('A single benchmark task definition (object or function)');
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Zod schema for validating benchmark suite structure
|
|
61
|
+
*/
|
|
62
|
+
const benchmarkSuiteSchema = z
|
|
63
|
+
.object({
|
|
64
|
+
benchmarks: z
|
|
65
|
+
.record(z.string(), benchmarkTaskSchema)
|
|
66
|
+
.describe('Map of benchmark task names to task definitions'),
|
|
67
|
+
config: partialModestBenchConfigSchema
|
|
68
|
+
.optional()
|
|
69
|
+
.describe('Suite-specific configuration overrides'),
|
|
70
|
+
metadata: z
|
|
71
|
+
.record(z.string(), z.unknown())
|
|
72
|
+
.optional()
|
|
73
|
+
.describe('Custom metadata associated with the suite'),
|
|
74
|
+
setup: benchmarkFnSchema
|
|
75
|
+
.optional()
|
|
76
|
+
.describe('Function to run before all benchmarks in the suite'),
|
|
77
|
+
tags: z
|
|
78
|
+
.array(z.string())
|
|
79
|
+
.optional()
|
|
80
|
+
.describe('Tags for filtering and grouping suites'),
|
|
81
|
+
teardown: benchmarkFnSchema
|
|
82
|
+
.optional()
|
|
83
|
+
.describe('Function to run after all benchmarks in the suite'),
|
|
84
|
+
})
|
|
85
|
+
.describe('A benchmark suite containing multiple tasks');
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Zod schema for validating benchmark file structure.
|
|
89
|
+
*
|
|
90
|
+
* Supports two formats:
|
|
91
|
+
*
|
|
92
|
+
* 1. Suite format (supports config/metadata/tags): { suites: { 'Suite Name': {
|
|
93
|
+
* benchmarks: {...} } }, config: {...} }
|
|
94
|
+
* 2. Flat format (simple, tasks only - no config/metadata/tags): { 'task name': ()
|
|
95
|
+
* => {...} }
|
|
96
|
+
*
|
|
97
|
+
* The flat format is automatically transformed to suite format with a default
|
|
98
|
+
* suite.
|
|
99
|
+
*
|
|
100
|
+
* Input: flat Record<string, function> OR suite object Output: always
|
|
101
|
+
* normalized to suite format
|
|
102
|
+
*/
|
|
103
|
+
export const benchmarkFileSchema = z
|
|
104
|
+
.union([
|
|
105
|
+
// Suite format: explicit structure with config/metadata/tags support
|
|
106
|
+
z.object({
|
|
107
|
+
config: partialModestBenchConfigSchema
|
|
108
|
+
.optional()
|
|
109
|
+
.describe('File-level configuration overrides'),
|
|
110
|
+
metadata: z
|
|
111
|
+
.record(z.string(), z.unknown())
|
|
112
|
+
.optional()
|
|
113
|
+
.describe('Custom metadata associated with the file'),
|
|
114
|
+
suites: z
|
|
115
|
+
.record(z.string(), benchmarkSuiteSchema)
|
|
116
|
+
.refine((suites) => Object.keys(suites).length > 0, {
|
|
117
|
+
message: 'At least one suite is required',
|
|
118
|
+
})
|
|
119
|
+
.describe('Map of suite names to suite definitions'),
|
|
120
|
+
tags: z
|
|
121
|
+
.array(z.string())
|
|
122
|
+
.optional()
|
|
123
|
+
.describe('Tags for filtering and grouping files'),
|
|
124
|
+
}),
|
|
125
|
+
// Flat format: simple tasks only (no config/metadata/tags)
|
|
126
|
+
z
|
|
127
|
+
.record(z.string(), benchmarkFnSchema)
|
|
128
|
+
.refine((tasks) => Object.keys(tasks).length > 0, {
|
|
129
|
+
message: 'At least one task is required',
|
|
130
|
+
})
|
|
131
|
+
.transform((tasks) => ({
|
|
132
|
+
// Ensure all optional properties exist (as undefined) for type consistency
|
|
133
|
+
config: undefined as Partial<ModestBenchConfig> | undefined,
|
|
134
|
+
metadata: undefined as Record<string, unknown> | undefined,
|
|
135
|
+
suites: {
|
|
136
|
+
default: {
|
|
137
|
+
benchmarks: Object.fromEntries(
|
|
138
|
+
Object.entries(tasks).map(([name, fn]) => [name, { fn }]),
|
|
139
|
+
),
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
tags: undefined as string[] | undefined,
|
|
143
|
+
})),
|
|
144
|
+
])
|
|
145
|
+
.describe(
|
|
146
|
+
'A benchmark file containing one or more suites with configuration and metadata',
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
// ============================================================================
|
|
150
|
+
// Type Exports
|
|
151
|
+
// ============================================================================
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Benchmark file definition (normalized) - internal representation Always in
|
|
155
|
+
* suite format
|
|
156
|
+
*/
|
|
157
|
+
export type BenchmarkDefinition = z.infer<typeof benchmarkFileSchema>;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Benchmark file definition (input) - what users write Can be either flat
|
|
161
|
+
* format (Record<string, function>) or suite format
|
|
162
|
+
*/
|
|
163
|
+
export type BenchmarkDefinitionInput = z.input<typeof benchmarkFileSchema>;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Benchmark suite (normalized) - internal representation
|
|
167
|
+
*/
|
|
168
|
+
export type BenchmarkSuite = z.infer<typeof benchmarkSuiteSchema>;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Benchmark suite (input) - what users write
|
|
172
|
+
*/
|
|
173
|
+
export type BenchmarkSuiteInput = z.input<typeof benchmarkSuiteSchema>;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Benchmark task (normalized) - internal representation Always an object with
|
|
177
|
+
* fn property
|
|
178
|
+
*/
|
|
179
|
+
export type BenchmarkTask = z.infer<typeof benchmarkTaskSchema>;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Benchmark task (input) - what users write Can be either a function or an
|
|
183
|
+
* object with fn property
|
|
184
|
+
*/
|
|
185
|
+
export type BenchmarkTaskInput = z.input<typeof benchmarkTaskSchema>;
|