Skip to content

Commit 55541c7

Browse files
feat: add CLAUDE.md
1 parent d56edda commit 55541c7

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

CLAUDE.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# CodSpeed Node Repository Layout
2+
3+
## Repository Structure
4+
5+
This is a monorepo containing CodSpeed plugins for various Node.js benchmarking frameworks.
6+
7+
### Root Level
8+
- `package.json` - Root package configuration
9+
- `pnpm-workspace.yaml` - PNPM workspace configuration
10+
- `lerna.json` - Lerna monorepo configuration
11+
- `tsconfig.base.json` - Base TypeScript configuration
12+
- `rollup.options.js` - Rollup bundler configuration
13+
- `scripts/` - Build and release scripts
14+
- `docs/` - Documentation files
15+
- `examples/` - Example projects using the plugins
16+
17+
### Packages (`packages/`)
18+
19+
#### Core Package (`packages/core/`)
20+
- **Purpose**: Core measurement and instrumentation functionality
21+
- **Key files**:
22+
- `src/index.ts` - Main exports, setupCore/teardownCore functions
23+
- `src/mongoMeasurement.ts` - MongoDB measurement handling
24+
- `src/optimization.ts` - Function optimization utilities
25+
- `src/native_core/` - Native C++ bindings for performance measurement
26+
- `src/introspection.ts` - V8 flags and runtime introspection
27+
28+
#### Tinybench Plugin (`packages/tinybench-plugin/`)
29+
- **Purpose**: CodSpeed integration for tinybench framework
30+
- **Key files**:
31+
- `src/index.ts` - Main plugin implementation with `withCodSpeed()` function
32+
- `tests/index.integ.test.ts` - Integration tests
33+
- `benches/` - Benchmark examples
34+
35+
#### Benchmark.js Plugin (`packages/benchmark.js-plugin/`)
36+
- **Purpose**: CodSpeed integration for benchmark.js framework
37+
- **Key files**:
38+
- `src/index.ts` - Main plugin implementation
39+
- `src/buildSuiteAdd.ts` - Suite building utilities
40+
41+
#### Vitest Plugin (`packages/vitest-plugin/`)
42+
- **Purpose**: CodSpeed integration for Vitest framework
43+
- **Key files**:
44+
- `src/index.ts` - Main plugin implementation
45+
- `src/runner.ts` - Custom test runner
46+
- `src/globalSetup.ts` - Global setup configuration
47+
48+
### Examples Directory (`examples/`)
49+
- `with-javascript-cjs/` - CommonJS JavaScript examples
50+
- `with-javascript-esm/` - ESM JavaScript examples
51+
- `with-typescript-cjs/` - CommonJS TypeScript examples
52+
- `with-typescript-esm/` - ESM TypeScript examples
53+
- `with-typescript-simple-cjs/` - Simple CommonJS TypeScript examples
54+
- `with-typescript-simple-esm/` - Simple ESM TypeScript examples
55+
56+
## Tinybench Plugin Architecture
57+
58+
### Current Stats/Measurements Access
59+
60+
The tinybench plugin currently has **limited stats exposure**:
61+
62+
1. **No direct stats API**: The `withCodSpeed()` function wraps a tinybench instance but doesn't expose measurement results
63+
2. **Console-only output**: Results are only printed to console via `console.log()`
64+
3. **Core measurement**: Uses `@codspeed/core` for actual measurement via:
65+
- `mongoMeasurement.start(uri)` / `mongoMeasurement.stop(uri)`
66+
- `Measurement.startInstrumentation()` / `Measurement.stopInstrumentation(uri)`
67+
68+
### Current Workflow
69+
1. User calls `withCodSpeed(new Bench())` to wrap their tinybench instance
70+
2. Plugin intercepts `bench.run()` to add CodSpeed instrumentation
71+
3. Each benchmark task runs with measurement instrumentation
72+
4. Results are logged to console but not returned as structured data
73+
74+
### Key Functions in tinybench plugin
75+
- `withCodSpeed(bench: Bench): Bench` - Main wrapper function
76+
- `setupInstruments(body)` - Dynamic instrument setup
77+
- `getCallingFile()` - Helper to generate unique URIs for benchmarks
78+
79+
## Potential Enhancement Areas
80+
81+
Based on the codebase analysis, to add stats access features:
82+
83+
1. **Extend return value**: Modify `bench.run()` to return structured measurement data
84+
2. **Add stats methods**: Add methods like `getStats()`, `getResults()`, `getLastRunStats()`
85+
3. **Integrate with core**: Leverage `@codspeed/core` measurement data
86+
4. **Maintain tinybench compatibility**: Ensure existing `bench.table()` still works

0 commit comments

Comments
 (0)