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

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.

toBeFasterThan() and toBeSlowerThan() matchers

Use toBeFasterThan() and toBeSlowerThan() matchers to assert relative performance between benchmarks. These matchers work with benchmark results from bench.compare().

Example of performance assertions

import { expect, test } from 'vitest' test('lib1 is faster than lib2', async ({ bench }) => { const result = await bench.compare( bench('lib1', () => { lib1() }), bench('lib2', () => { lib2() }), ) expect(result.get('lib1')).toBeFasterThan(result.get('lib2')) })

delta option for performance assertions

The delta option in toBeFasterThan() and toBeSlowerThan() specifies the minimum relative difference required for the assertion to pass. This helps avoid flaky tests caused by benchmark noise.

Example of delta option in performance assertions

// lib1 must be at least 10% faster than lib2 expect(result.get('lib1')).toBeFasterThan(result.get('lib2'), { delta: 0.1, }) // lib2 must be at least 20% slower than lib1 expect(result.get('lib2')).toBeSlowerThan(result.get('lib1'), { delta: 0.2, })

Absolute performance assertions with standard matchers

You can assert absolute performance using standard matchers like toBeGreaterThan(). Access benchmark result properties like throughput.mean.

Example of absolute performance assertion

test('parsing is fast enough', async ({ bench }) => { const result = await bench('parse', () => { parse(largeInput) }).run() expect(result.throughput.mean).toBeGreaterThan(10_000) })

Give your agent this brain