new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Vitest · Guide · all subjects

benchmarking/basics

6 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

bench fixture for defining benchmarks

Use the bench fixture from test context to define a benchmark. Call .run() to execute it. The bench() function registers a benchmark without executing it; calling .run() runs the benchmark and returns the result.

bench fixture only available in benchmark files

The bench fixture is only available in files matched by benchmark.include (default: **/*.{bench,benchmark}.?(c|m)[jt]s?(x)). Using { bench } inside a regular test file will throw an error. Whether a file participates in the benchmark run is decided by the filename.

Example of defining and running a benchmark

import { expect, test } from 'vitest' test('parsing performance', async ({ bench }) => { const result = await bench('parse', () => { JSON.parse('{"key":"value"}') }).run() })

Benchmarking with bench function

Vitest provides a bench function to run benchmark tests via Tinybench to compare performance results. Use describe to group bench functions together.

Benchmark example

import { bench, describe } from 'vitest' describe('sort', () => { bench('normal', () => { const x = [1, 5, 4, 2, 3] x.sort((a, b) => { return a - b }) }) bench('reverse', () => { const x = [1, 5, 4, 2, 3] x.reverse().sort((a, b) => { return a - b }) }) })

Benchmarking API rewrite in Vitest 5.0

The benchmarking API in Vitest 5.0 has been completely rewritten. The bench function is no longer a top-level import; instead, destructure bench from the test context inside a regular test(). Example: test('sort', async ({ bench }) => { await bench('sort', () => { [3, 1, 2].sort() }).run() }). Removed: bench.skip, bench.only, bench.todo (use test.skip/only/todo instead), benchmark.reporters, benchmark.outputFile, benchmark.compare config, --compare CLI flag, benchmark.outputJson config, --outputJson CLI flag, and Vitest instance mode property.

Give your agent this brain