Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
bench: |
pnpm turbo run bench --filter=@codspeed/vitest-plugin
pnpm --workspace-concurrency 1 -r bench-vitest
for ex in examples/with-vitest-*; do pnpm -C "$ex" bench-vitest || exit 1; done
- plugin: benchmark.js
bench: |
pnpm turbo run bench --filter=@codspeed/benchmark.js-plugin
Expand All @@ -48,6 +49,11 @@ jobs:
key-suffix: ${{ matrix.plugin }}
- run: pnpm install --frozen-lockfile --prefer-offline
- run: pnpm turbo run build
# Outside the root workspace; installed after the build so their copy of
# the plugin includes `dist/`.
- name: Install vitest examples
if: matrix.plugin == 'vitest'
run: for ex in examples/with-vitest-*; do pnpm -C "$ex" install --frozen-lockfile --prefer-offline; done

- name: Run simulation benchmarks
uses: CodSpeedHQ/action@main
Expand Down Expand Up @@ -76,8 +82,14 @@ jobs:
node-version-file: .nvmrc
- name: Restore turbo cache
uses: ./.github/actions/turbo-cache
# The native addon prebuild links against the host's libstdc++, which
# Turbo does not hash; keep GitHub's arm64 runners' builds out.
with:
key-suffix: codspeed-macro
- run: pnpm install --frozen-lockfile --prefer-offline
- run: pnpm turbo run build
- name: Install vitest examples
run: for ex in examples/with-vitest-*; do pnpm -C "$ex" install --frozen-lockfile --prefer-offline; done

- name: Run benchmarks
# use version from `main` branch to always test the latest version, in real projects, use a tag, like `@v2`
Expand All @@ -92,6 +104,7 @@ jobs:
pnpm turbo run bench --filter=@codspeed/benchmark.js-plugin
pnpm --workspace-concurrency 1 -r bench-tinybench
pnpm --workspace-concurrency 1 -r bench-vitest
for ex in examples/with-vitest-*; do pnpm -C "$ex" bench-vitest || exit 1; done

codspeed-walltime-macos:
runs-on: macos-latest
Expand Down Expand Up @@ -145,6 +158,8 @@ jobs:

- name: Restore turbo cache
uses: ./.github/actions/turbo-cache
with:
key-suffix: codspeed-macro

- name: Install repo dependencies
run: pnpm install --frozen-lockfile --prefer-offline
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,5 @@ packages/app/.env
# turbo
.turbo/
.rollup.cache/

.codspeed
23 changes: 22 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,25 @@ Based on the codebase analysis, to add stats access features:
- 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`).
- Run a task across all packages by omitting `--filter` (e.g. `pnpm turbo run build`).

## Testing a plugin during development

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`):

1. **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>`.
2. **Instrumentation / simulation.** `CODSPEED_ENV=true CODSPEED_RUNNER_MODE=simulation`
(or `instrumentation`). The plugin hijacks the run to do a single instrumented
pass per benchmark and prints `Measured/Checked <uri>` instead of the normal
harness output.
3. **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.
2 changes: 1 addition & 1 deletion examples/with-typescript-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"tinybench": "^4.0.1",
"tsx": "^4.23.12",
"typescript": "^5.1.3",
"vitest": "^4.0.18"
"vitest": "^5.0.0"
}
}
14 changes: 10 additions & 4 deletions examples/with-typescript-esm/src/fibonacci.bench.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { bench, describe } from "vitest";
import { recursiveFibonacci } from "./fibonacci";
import { describe, test } from "vitest";
import { recursiveFibonacci as recursiveFibonacciExport } from "./fibonacci";

// Imports are getters under Vite's module runner; read them once, outside the
// measured loop.
const recursiveFibonacci = recursiveFibonacciExport;

describe("recursiveFibonacci", () => {
bench("fibo 30", () => {
recursiveFibonacci(30);
test("fibo 30", async ({ bench }) => {
await bench("fibo 30", () => {
recursiveFibonacci(30);
}).run();
});
});
5 changes: 3 additions & 2 deletions examples/with-vitest-v3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"bench-vitest": "vitest bench --run"
},
"devDependencies": {
"@codspeed/vitest-plugin": "workspace:*",
"@codspeed/vitest-plugin": "file:../../packages/vitest-plugin",
"typescript": "^5.1.3",
"vitest": "^3.2.4"
}
},
"packageManager": "pnpm@10.12.4"
}
Loading
Loading