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/comparing

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.compare() for comparing multiple benchmarks

Use bench.compare() to compare multiple benchmarks against each other. When comparing benchmarks, Vitest runs them using interleaved iterations to reduce environmental bias (CPU throttling, GC pressure, etc.) and prints a comparison table after the test completes.

Example of bench.compare()

import { expect, test } from 'vitest' test('compare JSON libraries', async ({ bench }) => { const input = '{"key":"value","nested":{"a":1}}' const result = await bench.compare( bench('JSON.parse', () => { JSON.parse(input) }), bench('custom parser', () => { customParse(input) }), ) })

bench.compare() with options

Pass options as the last argument to bench.compare() to control iterations and time. Options include iterations (number of iterations) and time (time in milliseconds).

Example of bench.compare() with options

test('compare with options', async ({ bench }) => { const result = await bench.compare( bench('lib1', () => { lib1() }), bench('lib2', () => { lib2() }), { iterations: 100, time: 1000, }, ) })

Per-benchmark options in bench.compare()

Pass per-benchmark options as the second argument to bench() inside bench.compare(), matching how test() accepts options. Options can include beforeEach, afterEach, and other lifecycle hooks.

Example of bench.compare() with per-benchmark options

test('benchmarks with setup', async ({ bench }) => { const result = await bench.compare( bench('with-cache', () => { readFromCache() }), bench( 'without-cache', { beforeEach: () => clearCache() }, () => { readFromDisk() }, ), ) })

Give your agent this brain