-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.js
62 lines (53 loc) · 1.22 KB
/
bench.js
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
51
52
53
54
55
56
57
58
59
60
61
62
import { bench, run } from 'mitata'
import { staty, snapshot } from './src/index.js'
import { proxy, snapshot as valtioSnapshot } from 'valtio/vanilla'
const tinyObject = () => ({
name: 'batman',
count: 0
})
const bigObject = () => ({
name: 'batman',
count: 0,
deep: {
deep: {
deep: {
random: 1
}
},
map: new Map([[0, 'k0'], [1, 'k1']]),
set: new Set(['k0', 'k1'])
}
})
function suite (name, create, snapshot) {
bench(`${name} - create: tiny object`, () => create(tinyObject()))
bench(`${name} - create: complex object`, () => create(bigObject()))
{
const state = create(tinyObject())
bench(`${name} - update: tiny object`, () => {
state.count++
})
}
{
const state = create(bigObject())
bench(`${name} - update: big object`, () => {
state.count++
})
}
{
const state = create(tinyObject())
bench(`${name} - update + snapshot: tiny object`, () => {
state.count++
snapshot(state)
})
}
{
const state = create(bigObject())
bench(`${name} - update + snapshot: big object`, () => {
state.count++
snapshot(state)
})
}
}
suite('staty', staty, snapshot)
suite('valtio', proxy, valtioSnapshot)
run()