This is a monorepo containing CodSpeed plugins for various Node.js benchmarking frameworks.
package.json- Root package configurationpnpm-workspace.yaml- PNPM workspace configurationlerna.json- Lerna monorepo configurationtsconfig.base.json- Base TypeScript configurationrollup.options.js- Rollup bundler configurationscripts/- Build and release scriptsdocs/- Documentation filesexamples/- Example projects using the plugins
- Purpose: Core measurement and instrumentation functionality
- Key files:
src/index.ts- Main exports, setupCore/teardownCore functionssrc/mongoMeasurement.ts- MongoDB measurement handlingsrc/optimization.ts- Function optimization utilitiessrc/native_core/- Native C++ bindings for performance measurementsrc/introspection.ts- V8 flags and runtime introspection
- Purpose: CodSpeed integration for tinybench framework
- Key files:
src/index.ts- Main plugin implementation withwithCodSpeed()functiontests/index.integ.test.ts- Integration testsbenches/- Benchmark examples
- Purpose: CodSpeed integration for benchmark.js framework
- Key files:
src/index.ts- Main plugin implementationsrc/buildSuiteAdd.ts- Suite building utilities
- Purpose: CodSpeed integration for Vitest framework
- Key files:
src/index.ts- Main plugin implementationsrc/runner.ts- Custom test runnersrc/globalSetup.ts- Global setup configuration
with-javascript-cjs/- CommonJS JavaScript exampleswith-javascript-esm/- ESM JavaScript exampleswith-typescript-cjs/- CommonJS TypeScript exampleswith-typescript-esm/- ESM TypeScript exampleswith-typescript-simple-cjs/- Simple CommonJS TypeScript exampleswith-typescript-simple-esm/- Simple ESM TypeScript examples
The tinybench plugin currently has limited stats exposure:
- No direct stats API: The
withCodSpeed()function wraps a tinybench instance but doesn't expose measurement results - Console-only output: Results are only printed to console via
console.log() - Core measurement: Uses
@codspeed/corefor actual measurement via:mongoMeasurement.start(uri)/mongoMeasurement.stop(uri)Measurement.startInstrumentation()/Measurement.stopInstrumentation(uri)
- User calls
withCodSpeed(new Bench())to wrap their tinybench instance - Plugin intercepts
bench.run()to add CodSpeed instrumentation - Each benchmark task runs with measurement instrumentation
- Results are logged to console but not returned as structured data
withCodSpeed(bench: Bench): Bench- Main wrapper functionsetupInstruments(body)- Dynamic instrument setupgetCallingFile()- Helper to generate unique URIs for benchmarks
Based on the codebase analysis, to add stats access features:
- Extend return value: Modify
bench.run()to return structured measurement data - Add stats methods: Add methods like
getStats(),getResults(),getLastRunStats() - Integrate with core: Leverage
@codspeed/coremeasurement data - Maintain tinybench compatibility: Ensure existing
bench.table()still works
- Use pnpm instead of npm
- The monorepo uses Turborepo. Run a task for a single
package with a filter, using the package's full name (e.g.
@codspeed/tinybench-plugin):- Test:
pnpm turbo run test --filter=<package-name> - Build:
pnpm turbo run build --filter=<package-name> - Typecheck:
pnpm turbo run typecheck --filter=<package-name> - Lint:
pnpm turbo run lint --filter=<package-name> - Run a task across all packages by omitting
--filter(e.g.pnpm turbo run build).
- Test:
A plugin behaves differently depending on whether CodSpeed is driving the run,
so exercise all three of these when developing or reviewing a plugin change
(build the plugin first — the benches import from dist):
- Fallback (not under CodSpeed). No env vars. The plugin must stay out of
the way and let the framework run its benchmarks normally (no instrumentation,
no hijacked output). e.g.
pnpm turbo run bench --filter=<package-name>. - Instrumentation / simulation.
CODSPEED_ENV=true CODSPEED_RUNNER_MODE=simulation(orinstrumentation). The plugin hijacks the run to do a single instrumented pass per benchmark and printsMeasured/Checked <uri>instead of the normal harness output. - Walltime.
CODSPEED_ENV=true CODSPEED_RUNNER_MODE=walltime. The plugin instruments the framework's real benchmark loop and collects walltime results.
Running these locally outside the CodSpeed runner is expected to log
instrument-hooks: failed to write environment.json and skip actual measurement
writes — the point is to verify the plugin's control flow and output per mode,
not to produce real measurements.