deno.land / x / jotai@v1.8.4 / benchmarks / simple-write.ts

simple-write.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env npx ts-node
import { add, complete, cycle, save, suite } from 'benny'import { atom } from '../src/core/atom'import type { PrimitiveAtom } from '../src/core/atom'import { WRITE_ATOM, createStore } from '../src/core/store'
const createStateWithAtoms = (n: number) => { let targetAtom: PrimitiveAtom<number> | undefined const initialValues = new Map() for (let i = 0; i < n; ++i) { const a = atom(i) if (!targetAtom) { targetAtom = a } initialValues.set(a, i) } const store = createStore(initialValues) if (!targetAtom) { throw new Error() } return [store, targetAtom] as const}
const main = async () => { for (const n of [2, 3, 4, 5, 6]) { await suite( `simple-write-${n}`, add(`atoms=${10 ** n}`, () => { const [store, targetAtom] = createStateWithAtoms(10 ** n) return () => store[WRITE_ATOM](targetAtom, (c) => c + 1) }), cycle(), complete(), save({ folder: __dirname, file: `simple-write-${n}`, format: 'json', }), save({ folder: __dirname, file: `simple-write-${n}`, format: 'chart.html', }) ) }}
main()
jotai

Version Info

Tagged at
a year ago