Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

speed.bench.ts

34 lines939 Bytes

1import { afterAll, beforeAll, bench, describe } from 'vitest'
2import { setup } from './setup'
3​
4describe('client-nav', () => {
5 const test = setup()
6​
7 /**
8 * Running `vitest bench` ignores "suite hooks" like `beforeAll` and `afterAll`,
9 * so we use tinybench's `setup` and `teardown` options to run our setup and teardown logic.
10 *
11 * But CodSpeed calls the benchmarked function directly, bypassing `setup` and `teardown`,
12 * but it does support `beforeAll` and `afterAll`.
13 *
14 * So it looks like we're setting up in duplicate, but in reality, it's only running once per environment, as intended.
15 */
16​
17 beforeAll(test.before)
18 afterAll(test.after)
19​
20 bench(
21 'client-side navigation loop (react)',
22 async () => {
23 for (let i = 0; i < 10; i++) {
24 await test.tick()
25 }
26 },
27 {
28 warmupIterations: 100,
29 time: 10_000,
30 setup: test.before,
31 teardown: test.after,
32 },
33 )
34})