@benchsdk/runner 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ComputeSDK
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # @benchsdk/runner
2
+
3
+ Benchmark framework for authoring `*.bench.ts` files that report to the benchmarks platform via [`@benchsdk/client`](../benchsdk).
4
+
5
+ ## What it provides
6
+
7
+ - **`defineBenchmarkConfig`** / **`defineTask`** — A `*.bench.ts` file exports exactly two things: a **config** (`defineBenchmarkConfig`, the orchestration knobs + `participants` + an optional `onComplete` hook) and a **task** (`defineTask`, the workload for one iteration). There is no "mode": the orchestration shape (sequential / staggered / burst) emerges from the `iterations`, `concurrency`, and `staggerDelayMs` knobs, and `groupBy` (`'participant'` | `'round'`) selects the ordering across participants.
8
+ - **`bench run <file>`** — The CLI entrypoint. It imports the module, reads its `config` and `task`, applies CLI overrides, and drives the run. Benchmark files declare; they never call the runner themselves.
9
+ - **`TaskError`** / **`NoAvailableParticipantsError`** — Structured errors: throw `TaskError` from a task to attach a code / data / pre-measured steps; `bench run` treats `NoAvailableParticipantsError` (every participant env-gated out) as a clean no-op exit.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ pnpm add @benchsdk/runner @benchsdk/client
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ A benchmark file exports a `config` and a `task` — nothing else:
20
+
21
+ ```ts
22
+ import { defineBenchmarkConfig, defineTask } from '@benchsdk/runner';
23
+ import { providers } from './providers.js';
24
+ import { writeLegacyResults } from './legacy-results.js';
25
+
26
+ export const config = defineBenchmarkConfig({
27
+ benchmarkSlug: 'sandbox-tti-local',
28
+ benchmarkName: 'Sandbox TTI (local)',
29
+ iterations: 100, // total tasks per participant
30
+ concurrency: 1, // 1 = sequential, N = burst, N + staggerDelayMs = staggered
31
+ participants: providers,
32
+ // Aggregate post-run work (the one thing a single task can't see) lives here.
33
+ onComplete: (outcome) => writeLegacyResults(outcome.participants),
34
+ });
35
+
36
+ export const task = defineTask(async ({ participant, step, measure, log }) => {
37
+ log(`creating sandbox on ${participant.name}`);
38
+ // Named steps via `ctx.step`: values flow between steps with closures and
39
+ // cleanup runs in a `finally`. Each step is a first-class platform record
40
+ // with its own timing/status.
41
+ const sandbox = await step('create', () => participant.createCompute().sandbox.create());
42
+ try {
43
+ const t0 = performance.now();
44
+ await step('exec', () => sandbox.runCommand('node -v'));
45
+ measure({ ttiMs: performance.now() - t0 }); // metrics → the platform
46
+ } finally {
47
+ await step('destroy', () => sandbox.destroy());
48
+ }
49
+ });
50
+ ```
51
+
52
+ Run it with the CLI (flags override the config knobs):
53
+
54
+ ```sh
55
+ bench run benchmarks/sandbox/sandbox-tti.bench.ts --iterations 100 --concurrency 20 --provider e2b,modal
56
+ ```
57
+
58
+ To load a TypeScript benchmark without a build step, run the CLI under a TS loader:
59
+
60
+ ```sh
61
+ tsx node_modules/@benchsdk/runner/dist/bin.js run sandbox-tti.bench.ts
62
+ ```
63
+
64
+ ### Context channels
65
+
66
+ Inside a task the context exposes three separate channels:
67
+
68
+ - **`step(name, fn, options?)`** — returns `fn`'s value to your code (thread live objects between steps); records the step's timing/status on the platform. Return values are never auto-recorded as data.
69
+ - **`measure(data)`** — explicit metric channel. Called inside a `step()` it merges into that step's data; called at task top-level it merges into the task record. A task with no explicit steps is recorded as one implicit `'task'` step carrying its measurements.
70
+ - **`log(message, meta?)`** — human-readable narration to the run timeline.
71
+
72
+ ## License
73
+
74
+ MIT
package/dist/bin.cjs ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // src/bin.ts
5
+ var import_runner = require("@benchsdk/runner");
6
+ (0, import_runner.run)(process.argv.slice(2));
7
+ //# sourceMappingURL=bin.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n// Imports from the package entry (not a relative path) so the bin and any\n// benchmark module it loads share a single `@benchsdk/runner` instance — this\n// keeps `instanceof` checks (TaskError / NoAvailableParticipantsError) valid\n// across the bin and the dynamically imported `*.bench.ts`.\nimport { run } from '@benchsdk/runner';\n\nrun(process.argv.slice(2));\n"],"mappings":";;;;AAKA,oBAAoB;AAAA,IAEpB,mBAAI,QAAQ,KAAK,MAAM,CAAC,CAAC;","names":[]}
package/dist/bin.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/bin.ts
4
+ import { run } from "@benchsdk/runner";
5
+ run(process.argv.slice(2));
6
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n// Imports from the package entry (not a relative path) so the bin and any\n// benchmark module it loads share a single `@benchsdk/runner` instance — this\n// keeps `instanceof` checks (TaskError / NoAvailableParticipantsError) valid\n// across the bin and the dynamically imported `*.bench.ts`.\nimport { run } from '@benchsdk/runner';\n\nrun(process.argv.slice(2));\n"],"mappings":";;;AAKA,SAAS,WAAW;AAEpB,IAAI,QAAQ,KAAK,MAAM,CAAC,CAAC;","names":[]}