Skip to content

top level bench prints result twice #9718

@marcalexiei

Description

@marcalexiei

Describe the bug

When bench is invoked at the top of the module his results are displayed twice.

Wrapping the bench call in a describe doesn't duplicate the results.

sum-without-describe.bench.ts

import { bench } from "vitest";

bench("sum", () => {
  1 + 1;
});

sum-with-describe.bench.ts

import { bench, describe } from "vitest";

describe("sum", () => {
  bench("a", () => {
    1 + 1;
  });
});

Result

 ✓ tests/sum-with-describe.bench.ts > sum 5789ms
     name             hz     min     max    mean     p75     p99    p995    p999     rme   samples
   · a     48,128,806.17  0.0000  0.0327  0.0000  0.0000  0.0000  0.0000  0.0001  ±0.05%  24064404

 ✓ tests/sum-without-describe.bench.ts 5748ms
     name             hz     min     max    mean     p75     p99    p995    p999     rme   samples
   · sum   48,075,917.04  0.0000  0.0334  0.0000  0.0000  0.0000  0.0000  0.0001  ±0.05%  24037959

 ✓ tests/sum-without-describe.bench.ts 5748ms
     name             hz     min     max    mean     p75     p99    p995    p999     rme   samples
   · sum   48,075,917.04  0.0000  0.0334  0.0000  0.0000  0.0000  0.0000  0.0001  ±0.05%  24037959

Reproduction

Code: https://github.com/marcalexiei/vitest-bench-playground
GitHub actions: https://github.com/marcalexiei/vitest-bench-playground/actions/runs/22277251116/job/64441360076

System Info

System:
    OS: macOS 26.3
    CPU: (8) arm64 Apple M3
    Memory: 139.19 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.12.0 - /.nvm/versions/node/v24.12.0/bin/node
    npm: 11.6.2 - /.nvm/versions/node/v24.12.0/bin/npm
    pnpm: 10.28.2 - /.nvm/versions/node/v24.12.0/bin/pnpm
  Browsers:
    Chrome: 144.0.7559.133
    Safari: 26.3
  npmPackages:
    vitest: 4.0.18 => 4.0.18

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions