@codspeed/vitest-plugin

v3.1.1
vitest plugin for CodSpeed
codspeed benchmark vitest performance

@codspeed/vitest-plugin

Vitest plugin for CodSpeed

CI npm (scoped) Discord CodSpeed Badge

Documentation

Check out the documentation for complete integration instructions.

Installation

First, install the plugin @codspeed/vitest-plugin and vitest (if not already installed):

[!NOTE] The CodSpeed plugin is only compatible with [email protected] and above.

npm install --save-dev @codspeed/vitest-plugin vitest

or with yarn:

yarn add --dev @codspeed/vitest-plugin vitest

or with pnpm:

pnpm add --save-dev @codspeed/vitest-plugin vitest

Usage

Let's create a fibonacci function and benchmark it with vitest.bench:

import { describe, bench } from "vitest";

function fibonacci(n: number): number {
  if (n < 2) {
    return n;
  }
  return fibonacci(n - 1) + fibonacci(n - 2);
}

describe("fibonacci", () => {
  bench("fibonacci10", () => {
    fibonacci(10);
  });

  bench("fibonacci15", () => {
    fibonacci(15);
  });
});

Create or update your vitest.config.ts file to use the CodSpeed runner:

import { defineConfig } from "vitest/config";
import codspeedPlugin from "@codspeed/vitest-plugin";

export default defineConfig({
  plugins: [codspeedPlugin()],
  // ...
});

Finally, run your benchmarks (here with pnpm):

$ pnpm vitest bench --run
[CodSpeed] bench detected but no instrumentation found, falling back to default vitest runner

... Regular `vitest bench` output

And... Congrats 🎉, CodSpeed is installed in your benchmarking suite! Locally, CodSpeed will fallback to vitest since the instrumentation is only available in the CI environment for now.

You can now run those benchmarks in your CI to continuously get consistent performance measurements.

npm i @codspeed/vitest-plugin

Metadata

  • Apache-2.0
  • Whatever
  • Adrien Cacciaguerra
  • released 7/22/2024

Downloads