@effect-bench/node 0.0.0 → 0.0.2

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 +93 -0
  2. package/package.json +4 -3
package/README.md ADDED
@@ -0,0 +1,93 @@
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/user.bench.ts
9
+ import { Bench } from '@effect-bench/core'
10
+ import { Effect, Schema } from 'effect'
11
+
12
+ const User = Schema.Struct({ id: Schema.Number, email: Schema.String, tags: Schema.Array(Schema.String) })
13
+ const user = { id: 1, email: 'ada@example.com', tags: ['admin'] }
14
+ const decodeSync = Schema.decodeUnknownSync(User)
15
+ const decodeEffect = Schema.decodeUnknownEffect(User)
16
+
17
+ export default Bench.suite('userSchema')(
18
+ Bench.group('decode', { baseline: 'sync' })(
19
+ Bench.sync('sync', () => decodeSync(user)),
20
+ Bench.make('effect', () => decodeEffect(user)),
21
+ ),
22
+ Bench.params('stringify', { rows: [10, 1000] }, {
23
+ prepare: ({ rows }) => Effect.succeed(Array.from({ length: rows }, () => user)), // untimed
24
+ sync: users => JSON.stringify(users), // timed
25
+ budget: { p99: '5 millis' },
26
+ }),
27
+ )
28
+ ```
29
+
30
+ ```bash
31
+ effect-bench list
32
+ effect-bench run --save before # store a baseline
33
+ effect-bench run --compare before --json
34
+ effect-bench check --compare before # exit 1 on a regression or blown budget
35
+ effect-bench run --rigorous --forks 8 # more processes for a tighter interval
36
+ ```
37
+
38
+ ## Writing benches
39
+
40
+ | Constructor | Measures |
41
+ | --- | --- |
42
+ | `Bench.make(name, effect)` | re-runs one Effect value |
43
+ | `Bench.make(name, ctx => effect)` | builds and runs a fresh Effect per operation |
44
+ | `Bench.sync(name, ctx => value)` | a plain function |
45
+ | `Bench.params(name, matrix, { prepare?, run \| sync })` | one bench per combination, ids like `stringify[rows=1000]` |
46
+ | `Bench.group(name, { baseline })(...)` | alternatives, reported as a ratio to the baseline |
47
+
48
+ `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.
49
+
50
+ Options (suite or bench): `samples`, `minTime`, `warmup`, `memory` (GC + heap delta per sample), `budget: { p50, p99 }`, `tags`, and `check` (validates one result before timing).
51
+
52
+ ## Output
53
+
54
+ `--json` prints one record per line on stdout: a `result` per bench and a final `summary`. Logs go to stderr.
55
+
56
+ ```json
57
+ {"type":"result","schemaVersion":2,"status":"ok","id":"userSchema/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":"userSchema/decode/sync","ratio":5.1}}
58
+ {"type":"summary","schemaVersion":2,"total":4,"failed":0,"regressions":1,"budgetsExceeded":0,"stale":0,"exitCode":1}
59
+ ```
60
+
61
+ ## How verdicts work
62
+
63
+ 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.
64
+
65
+ `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`.
66
+
67
+ `--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.
68
+
69
+ Exit codes: `0` ok, `1` regression or blown budget, `2` failed bench or error, `3` baseline recorded on another runtime or machine.
70
+
71
+ ## Config
72
+
73
+ Optional `effect-bench.config.ts` in the working directory:
74
+
75
+ ```ts
76
+ import { BenchConfig } from '@effect-bench/cli'
77
+
78
+ export default BenchConfig.make({
79
+ include: ['**/bench/*.bench.ts'],
80
+ modes: { ci: { samples: 50, minTime: '1 second', forks: 5 } },
81
+ noiseThreshold: 0.05,
82
+ })
83
+ ```
84
+
85
+ ## Packages
86
+
87
+ - `@effect-bench/core` — DSL, measuring loop, stats, comparison, runner, reporters. No platform imports.
88
+ - `@effect-bench/node` — hrtime clock, GC and heap, environment fingerprint, file baseline store.
89
+ - `@effect-bench/cli` — `effect-bench` command.
90
+
91
+ ## Known limitations
92
+
93
+ - 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.2",
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.2"
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
  }