Skip to content

Commit b680ed8

Browse files
test(vitest-plugin): add with-vitest-v5 example
Benchmark the plugin against Vitest 5 in CI the way the v3 and v4 examples do for their majors, using the `bench` fixture and `bench.compare()`. Refs COD-2931 Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0551706 commit b680ed8

6 files changed

Lines changed: 117 additions & 15 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "with-vitest-v5",
3+
"private": true,
4+
"type": "module",
5+
"scripts": {
6+
"bench-vitest": "vitest bench --run"
7+
},
8+
"devDependencies": {
9+
"@codspeed/vitest-plugin": "workspace:*",
10+
"typescript": "^5.1.3",
11+
"vitest": "^5.0.0"
12+
},
13+
"dependenciesMeta": {
14+
"@codspeed/vitest-plugin": {
15+
"injected": true
16+
}
17+
}
18+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { describe, test } from "vitest";
2+
import {
3+
iterativeFibonacci as iterativeFibonacciExport,
4+
recursiveFibonacci as recursiveFibonacciExport,
5+
} from "./fibonacci";
6+
7+
// Imports are getters under Vite's module runner; read them once, outside the
8+
// measured loop.
9+
const recursiveFibonacci = recursiveFibonacciExport;
10+
const iterativeFibonacci = iterativeFibonacciExport;
11+
12+
describe("fibonacci", () => {
13+
test("fibo 15", async ({ bench }) => {
14+
await bench.compare(
15+
bench("recursive", () => {
16+
recursiveFibonacci(15);
17+
}),
18+
bench("iterative", () => {
19+
iterativeFibonacci(15);
20+
}),
21+
);
22+
});
23+
24+
test("fibo 20", async ({ bench }) => {
25+
await bench.compare(
26+
bench("recursive", () => {
27+
recursiveFibonacci(20);
28+
}),
29+
bench("iterative", () => {
30+
iterativeFibonacci(20);
31+
}),
32+
);
33+
});
34+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export function recursiveFibonacci(n: number): number {
2+
if (n < 2) {
3+
return n;
4+
}
5+
return recursiveFibonacci(n - 1) + recursiveFibonacci(n - 2);
6+
}
7+
8+
export function iterativeFibonacci(n: number): number {
9+
let a = 0;
10+
let b = 1;
11+
for (let i = 0; i < n; i++) {
12+
const temp = a + b;
13+
a = b;
14+
b = temp;
15+
}
16+
return a;
17+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["es2023"],
4+
"module": "ESNext",
5+
"verbatimModuleSyntax": true,
6+
"target": "es2022",
7+
"strict": true,
8+
"esModuleInterop": true,
9+
"skipLibCheck": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"moduleResolution": "Node"
12+
}
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import codspeedPlugin from "@codspeed/vitest-plugin";
2+
import { defineConfig } from "vitest/config";
3+
4+
export default defineConfig({
5+
plugins: [codspeedPlugin()],
6+
});

‎pnpm-lock.yaml‎

Lines changed: 29 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)