@effect-bench/node 0.0.0 → 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.
Files changed (2) hide show
  1. package/README.md +88 -0
  2. package/package.json +4 -3
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # effect-bench
2
+
3
+ Benchmarks for [Effect](https://effect.website) code, with JSON output and baseline verdicts built for agents and CI.
4
+
5
+ Community project, not affiliated with the Effect team.
6
+
7
+ ```ts
8
+ // bench/schema.bench.ts
9
+ import { Bench } from '@effect-bench/core'
10
+ import { Effect } from 'effect'
11
+
12
+ export default Bench.suite('workflowCompiler', { layer: NodeRegistry.layer })(
13
+ Bench.params('compile', { nodes: [10, 100, 1000] }, {
14
+ prepare: ({ nodes }) => Effect.succeed(makeDraft(nodes)), // untimed
15
+ run: draft => compile(draft), // timed
16
+ }),
17
+ Bench.group('decode', { baseline: 'sync' })(
18
+ Bench.sync('sync', () => decodeSync(lead)),
19
+ Bench.make('effect', () => decodeEffect(lead)),
20
+ ),
21
+ Bench.sync('encode', () => encode(payload), { budget: { p99: '5 millis' } }),
22
+ )
23
+ ```
24
+
25
+ ```bash
26
+ effect-bench list
27
+ effect-bench run --save before # store a baseline
28
+ effect-bench run --compare before --json
29
+ effect-bench check --compare before # exit 1 on a regression or blown budget
30
+ effect-bench run --rigorous --forks 8 # more processes for a tighter interval
31
+ ```
32
+
33
+ ## Writing benches
34
+
35
+ | Constructor | Measures |
36
+ | --- | --- |
37
+ | `Bench.make(name, effect)` | re-runs one Effect value |
38
+ | `Bench.make(name, ctx => effect)` | builds and runs a fresh Effect per operation |
39
+ | `Bench.sync(name, ctx => value)` | a plain function |
40
+ | `Bench.params(name, matrix, { prepare?, run \| sync })` | one bench per combination, ids like `compile[nodes=100]` |
41
+ | `Bench.group(name, { baseline })(...)` | alternatives, reported as a ratio to the baseline |
42
+
43
+ `Bench.suite(name, { layer, setup, ...options })` builds `layer` once per suite and runs `setup` in the suite's scope; its result is the `ctx` each bench receives. Benches can only use services the layer provides — anything else is a type error.
44
+
45
+ Options (suite or bench): `samples`, `minTime`, `warmup`, `memory` (GC + heap delta per sample), `budget: { p50, p99 }`, `tags`, and `check` (validates one result before timing).
46
+
47
+ ## Output
48
+
49
+ `--json` prints one record per line on stdout: a `result` per bench and a final `summary`. Logs go to stderr.
50
+
51
+ ```json
52
+ {"type":"result","schemaVersion":1,"status":"ok","id":"leadSchema/decode/effect","stats":{"medianNs":858,"p99Ns":943,"opsPerSec":1165161,...},"comparison":{"baseline":"before","change":0.051,"ci":[0.039,0.058],"verdict":"slower","stale":false},"relative":{"baselineId":"leadSchema/decode/sync","ratio":5.1}}
53
+ {"type":"summary","schemaVersion":1,"total":4,"failed":0,"regressions":1,"budgetsExceeded":0,"stale":0,"exitCode":1}
54
+ ```
55
+
56
+ ## How verdicts work
57
+
58
+ The CLI measures each suite in several fresh processes (`--forks`, default 3; 6 with `--rigorous`), interleaved fork by fork so slow drift spreads across suites. Drift between processes — JIT decisions, CPU frequency — is much larger than noise within one run, so each fork's median counts as one observation: the 95% interval for the change is a pooled t-interval on log medians.
59
+
60
+ `faster`/`slower` only when the whole interval is beyond the noise threshold (`--threshold`, default 3%), `same` when it is inside, `inconclusive` otherwise. On a laptop with 3 forks per side, repeated comparisons of unchanged code gave no false verdicts in 96 tries; a 15% slowdown was flagged every time and a 5% one most of the time (otherwise `inconclusive`). Treat `inconclusive` as "measure more": `--rigorous` or more `--forks`.
61
+
62
+ `--forks 0` measures in the CLI process, and `Runner.run` does the same when called from code. With a single fork on both sides the interval only sees within-run noise and will overstate confidence.
63
+
64
+ Exit codes: `0` ok, `1` regression or blown budget, `2` failed bench or error, `3` baseline recorded on another runtime or machine.
65
+
66
+ ## Config
67
+
68
+ Optional `effect-bench.config.ts` in the working directory:
69
+
70
+ ```ts
71
+ import { BenchConfig } from '@effect-bench/cli'
72
+
73
+ export default BenchConfig.make({
74
+ include: ['**/bench/*.bench.ts'],
75
+ modes: { ci: { samples: 50, minTime: '1 second', forks: 5 } },
76
+ noiseThreshold: 0.05,
77
+ })
78
+ ```
79
+
80
+ ## Packages
81
+
82
+ - `@effect-bench/core` — DSL, measuring loop, stats, comparison, runner, reporters. No platform imports.
83
+ - `@effect-bench/node` — hrtime clock, GC and heap, environment fingerprint, file baseline store.
84
+ - `@effect-bench/cli` — `effect-bench` command.
85
+
86
+ ## Known limitations
87
+
88
+ - Bench files are loaded with Node's built-in type stripping, so they must use erasable TypeScript syntax only.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-bench/node",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -9,7 +9,7 @@
9
9
  }
10
10
  },
11
11
  "dependencies": {
12
- "@effect-bench/core": "0.0.0"
12
+ "@effect-bench/core": "0.0.1"
13
13
  },
14
14
  "peerDependencies": {
15
15
  "effect": "^4.1.2",
@@ -25,5 +25,6 @@
25
25
  ],
26
26
  "publishConfig": {
27
27
  "access": "public"
28
- }
28
+ },
29
+ "scripts": {}
29
30
  }