@effect-bench/node 0.0.0-stage → 0.0.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.
@@ -0,0 +1,9 @@
1
+ import { FileSystem, Layer, Path } from 'effect';
2
+ export declare const clock: Layer.Layer<never, never, never>;
3
+ export declare const memory: Layer.Layer<never, never, never>;
4
+ export declare const environment: Layer.Layer<never, never, never>;
5
+ export declare const baselineStore: (directory?: string) => Layer.Layer<never, never, FileSystem.FileSystem | Path.Path>;
6
+ export declare const layer: (options?: {
7
+ readonly baselineDirectory?: string;
8
+ }) => Layer.Layer<never, never, never>;
9
+ //# sourceMappingURL=NodeBench.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeBench.d.ts","sourceRoot":"","sources":["../../src/NodeBench.ts"],"names":[],"mappings":"AAMA,OAAO,EAAU,UAAU,EAAE,KAAK,EAAU,IAAI,EAAU,MAAM,QAAQ,CAAA;AAExE,eAAO,MAAM,KAAK,kCAIhB,CAAA;AAYF,eAAO,MAAM,MAAM,kCAGhB,CAAA;AAUH,eAAO,MAAM,WAAW,kCAetB,CAAA;AAIF,eAAO,MAAM,aAAa,sFAwBvB,CAAA;AAEH,eAAO,MAAM,KAAK,aAAa;IAAE,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAAE,qCAGnE,CAAA"}
@@ -0,0 +1,73 @@
1
+ import { execFileSync } from 'node:child_process';
2
+ import os from 'node:os';
3
+ import { setFlagsFromString } from 'node:v8';
4
+ import { runInNewContext } from 'node:vm';
5
+ import { Baseline, BaselineError, BaselineStore, BenchClock, BenchEnvironment, BenchMemory } from '@effect-bench/core';
6
+ import { NodeServices } from '@effect/platform-node';
7
+ import { Effect, FileSystem, Layer, Option, Path, Schema } from 'effect';
8
+ export const clock = Layer.sync(BenchClock, () => {
9
+ // Offset from layer creation so the value stays well inside float precision.
10
+ const origin = process.hrtime.bigint();
11
+ return { nowNs: () => Number(process.hrtime.bigint() - origin) };
12
+ });
13
+ const exposeGc = () => {
14
+ if (typeof globalThis.gc === 'function')
15
+ return globalThis.gc;
16
+ try {
17
+ setFlagsFromString('--expose-gc');
18
+ return runInNewContext('gc');
19
+ }
20
+ catch {
21
+ return undefined;
22
+ }
23
+ };
24
+ export const memory = Layer.sync(BenchMemory, () => ({
25
+ gc: exposeGc(),
26
+ heapUsed: () => process.memoryUsage().heapUsed,
27
+ }));
28
+ const git = (args) => {
29
+ try {
30
+ return execFileSync('git', args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ };
36
+ export const environment = Layer.succeed(BenchEnvironment, {
37
+ fingerprint: Effect.sync(() => {
38
+ const cpus = os.cpus();
39
+ const status = git(['status', '--porcelain']);
40
+ return {
41
+ runtime: typeof process.versions['bun'] === 'string' ? 'bun' : 'node',
42
+ runtimeVersion: process.version,
43
+ platform: process.platform,
44
+ arch: process.arch,
45
+ cpu: cpus[0]?.model.trim() ?? 'unknown',
46
+ cpus: cpus.length,
47
+ gitSha: git(['rev-parse', 'HEAD']),
48
+ gitDirty: status === null ? null : status.length > 0,
49
+ };
50
+ }),
51
+ });
52
+ const BaselineJson = Schema.fromJsonString(Baseline);
53
+ export const baselineStore = (directory = '.bench/baselines') => Layer.effect(BaselineStore, Effect.gen(function* () {
54
+ const fs = yield* FileSystem.FileSystem;
55
+ const path = yield* Path.Path;
56
+ const fileOf = (name) => path.join(directory, `${name}.json`);
57
+ const failure = (name, message) => (cause) => new BaselineError({ name, message, cause });
58
+ return {
59
+ save: baseline => Effect.gen(function* () {
60
+ const json = yield* Schema.encodeEffect(BaselineJson)(baseline);
61
+ yield* fs.makeDirectory(directory, { recursive: true });
62
+ yield* fs.writeFileString(fileOf(baseline.name), json);
63
+ }).pipe(Effect.mapError(failure(baseline.name, `Could not save baseline "${baseline.name}".`))),
64
+ load: name => Effect.gen(function* () {
65
+ if (!(yield* fs.exists(fileOf(name))))
66
+ return Option.none();
67
+ const json = yield* fs.readFileString(fileOf(name));
68
+ return Option.some(yield* Schema.decodeUnknownEffect(BaselineJson)(json));
69
+ }).pipe(Effect.mapError(failure(name, `Could not load baseline "${name}".`))),
70
+ };
71
+ }));
72
+ export const layer = (options = {}) => Layer.mergeAll(clock, memory, environment, baselineStore(options.baselineDirectory)).pipe(Layer.provide(NodeServices.layer));
73
+ //# sourceMappingURL=NodeBench.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NodeBench.js","sourceRoot":"","sources":["../../src/NodeBench.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AACtH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAExE,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE;IAC/C,6EAA6E;IAC7E,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,CAAA;IACtC,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,MAAM,CAAC,EAAE,CAAA;AAClE,CAAC,CAAC,CAAA;AAEF,MAAM,QAAQ,GAAG,GAA6B,EAAE;IAC9C,IAAI,OAAO,UAAU,CAAC,EAAE,KAAK,UAAU;Q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@@ -0,0 +1,2 @@
1
+ export * as NodeBench from './NodeBench.ts';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * as NodeBench from './NodeBench.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,29 @@
1
1
  {
2
2
  "name": "@effect-bench/node",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./dist/src/index.d.ts",
8
+ "default": "./dist/src/index.js"
9
+ }
10
+ },
11
+ "dependencies": {
12
+ "@effect-bench/core": "0.0.0"
13
+ },
14
+ "peerDependencies": {
15
+ "effect": "^4.1.2",
16
+ "@effect/platform-node": "^4.1.2"
17
+ },
18
+ "devDependencies": {
19
+ "effect": "4.1.2",
20
+ "@effect/platform-node": "4.1.2"
21
+ },
22
+ "files": [
23
+ "dist/src",
24
+ "src"
25
+ ],
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
6
29
  }
@@ -0,0 +1,86 @@
1
+ import { execFileSync } from 'node:child_process'
2
+ import os from 'node:os'
3
+ import { setFlagsFromString } from 'node:v8'
4
+ import { runInNewContext } from 'node:vm'
5
+ import { Baseline, BaselineError, BaselineStore, BenchClock, BenchEnvironment, BenchMemory } from '@effect-bench/core'
6
+ import { NodeServices } from '@effect/platform-node'
7
+ import { Effect, FileSystem, Layer, Option, Path, Schema } from 'effect'
8
+
9
+ export const clock = Layer.sync(BenchClock, () => {
10
+ // Offset from layer creation so the value stays well inside float precision.
11
+ const origin = process.hrtime.bigint()
12
+ return { nowNs: () => Number(process.hrtime.bigint() - origin) }
13
+ })
14
+
15
+ const exposeGc = (): (() => void) | undefined => {
16
+ if (typeof globalThis.gc === 'function') return globalThis.gc
17
+ try {
18
+ setFlagsFromString('--expose-gc')
19
+ return runInNewContext('gc') as () => void
20
+ } catch {
21
+ return undefined
22
+ }
23
+ }
24
+
25
+ export const memory = Layer.sync(BenchMemory, () => ({
26
+ gc: exposeGc(),
27
+ heapUsed: () => process.memoryUsage().heapUsed,
28
+ }))
29
+
30
+ const git = (args: ReadonlyArray<string>): string | null => {
31
+ try {
32
+ return execFileSync('git', args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim()
33
+ } catch {
34
+ return null
35
+ }
36
+ }
37
+
38
+ export const environment = Layer.succeed(BenchEnvironment, {
39
+ fingerprint: Effect.sync(() => {
40
+ const cpus = os.cpus()
41
+ const status = git(['status', '--porcelain'])
42
+ return {
43
+ runtime: typeof process.versions['bun'] === 'string' ? 'bun' : 'node',
44
+ runtimeVersion: process.version,
45
+ platform: process.platform,
46
+ arch: process.arch,
47
+ cpu: cpus[0]?.model.trim() ?? 'unknown',
48
+ cpus: cpus.length,
49
+ gitSha: git(['rev-parse', 'HEAD']),
50
+ gitDirty: status === null ? null : status.length > 0,
51
+ }
52
+ }),
53
+ })
54
+
55
+ const BaselineJson = Schema.fromJsonString(Baseline)
56
+
57
+ export const baselineStore = (directory = '.bench/baselines') =>
58
+ Layer.effect(
59
+ BaselineStore,
60
+ Effect.gen(function* () {
61
+ const fs = yield* FileSystem.FileSystem
62
+ const path = yield* Path.Path
63
+ const fileOf = (name: string) => path.join(directory, `${name}.json`)
64
+ const failure = (name: string, message: string) => (cause: unknown) => new BaselineError({ name, message, cause })
65
+
66
+ return {
67
+ save: baseline =>
68
+ Effect.gen(function* () {
69
+ const json = yield* Schema.encodeEffect(BaselineJson)(baseline)
70
+ yield* fs.makeDirectory(directory, { recursive: true })
71
+ yield* fs.writeFileString(fileOf(baseline.name), json)
72
+ }).pipe(Effect.mapError(failure(baseline.name, `Could not save baseline "${baseline.name}".`))),
73
+ load: name =>
74
+ Effect.gen(function* () {
75
+ if (!(yield* fs.exists(fileOf(name)))) return Option.none()
76
+ const json = yield* fs.readFileString(fileOf(name))
77
+ return Option.some(yield* Schema.decodeUnknownEffect(BaselineJson)(json))
78
+ }).pipe(Effect.mapError(failure(name, `Could not load baseline "${name}".`))),
79
+ }
80
+ })
81
+ )
82
+
83
+ export const layer = (options: { readonly baselineDirectory?: string } = {}) =>
84
+ Layer.mergeAll(clock, memory, environment, baselineStore(options.baselineDirectory)).pipe(
85
+ Layer.provide(NodeServices.layer)
86
+ )
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * as NodeBench from './NodeBench.ts'
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.