|
1 | | -import { createSelector } from '@reduxjs/toolkit' |
2 | | -import { bench } from 'vitest' |
3 | | -import { autotrackMemoize } from '../src/autotrackMemoize/autotrackMemoize' |
4 | | -import { weakMapMemoize } from '../src/weakMapMemoize' |
5 | | - |
6 | | -describe('bench', () => { |
7 | | - interface State { |
8 | | - todos: { |
9 | | - id: number |
10 | | - completed: boolean |
11 | | - }[] |
12 | | - } |
13 | | - const state: State = { |
14 | | - todos: [ |
15 | | - { id: 0, completed: false }, |
16 | | - { id: 1, completed: false } |
17 | | - ] |
18 | | - } |
19 | | - bench( |
20 | | - 'selectorDefault', |
21 | | - () => { |
22 | | - const selectorDefault = createSelector( |
23 | | - (state: State) => state.todos, |
24 | | - todos => todos.map(t => t.id) |
25 | | - ) |
26 | | - selectorDefault(state) |
27 | | - }, |
28 | | - { iterations: 500 } |
29 | | - ) |
30 | | - |
31 | | - bench( |
32 | | - 'selectorAutotrack', |
33 | | - () => { |
34 | | - const selectorAutotrack = createSelector( |
35 | | - (state: State) => state.todos, |
36 | | - todos => todos.map(t => t.id), |
37 | | - { memoize: autotrackMemoize } |
38 | | - ) |
39 | | - selectorAutotrack(state) |
40 | | - }, |
41 | | - { iterations: 500 } |
42 | | - ) |
43 | | - |
44 | | - bench( |
45 | | - 'selectorWeakMap', |
46 | | - () => { |
47 | | - const selectorWeakMap = createSelector( |
48 | | - (state: State) => state.todos, |
49 | | - todos => todos.map(t => t.id), |
50 | | - { memoize: weakMapMemoize } |
51 | | - ) |
52 | | - selectorWeakMap(state) |
53 | | - }, |
54 | | - { iterations: 500 } |
55 | | - ) |
56 | | -}) |
| 1 | +import { createSelector } from '@reduxjs/toolkit' |
| 2 | +import { bench } from 'vitest' |
| 3 | +import { autotrackMemoize } from '../src/autotrackMemoize/autotrackMemoize' |
| 4 | +import { weakMapMemoize } from '../src/weakMapMemoize' |
| 5 | + |
| 6 | +describe('bench', () => { |
| 7 | + interface State { |
| 8 | + todos: { |
| 9 | + id: number |
| 10 | + completed: boolean |
| 11 | + }[] |
| 12 | + } |
| 13 | + const state: State = { |
| 14 | + todos: [ |
| 15 | + { id: 0, completed: false }, |
| 16 | + { id: 1, completed: false } |
| 17 | + ] |
| 18 | + } |
| 19 | + bench( |
| 20 | + 'selectorDefault', |
| 21 | + () => { |
| 22 | + const selectorDefault = createSelector( |
| 23 | + (state: State) => state.todos, |
| 24 | + todos => todos.map(t => t.id) |
| 25 | + ) |
| 26 | + selectorDefault(state) |
| 27 | + }, |
| 28 | + { iterations: 500 } |
| 29 | + ) |
| 30 | + |
| 31 | + bench( |
| 32 | + 'selectorAutotrack', |
| 33 | + () => { |
| 34 | + const selectorAutotrack = createSelector( |
| 35 | + (state: State) => state.todos, |
| 36 | + todos => todos.map(t => t.id), |
| 37 | + { memoize: autotrackMemoize } |
| 38 | + ) |
| 39 | + selectorAutotrack(state) |
| 40 | + }, |
| 41 | + { iterations: 500 } |
| 42 | + ) |
| 43 | + |
| 44 | + bench( |
| 45 | + 'selectorWeakMap', |
| 46 | + () => { |
| 47 | + const selectorWeakMap = createSelector( |
| 48 | + (state: State) => state.todos, |
| 49 | + todos => todos.map(t => t.id), |
| 50 | + { memoize: weakMapMemoize } |
| 51 | + ) |
| 52 | + selectorWeakMap(state) |
| 53 | + }, |
| 54 | + { iterations: 500 } |
| 55 | + ) |
| 56 | +}) |
0 commit comments