Skip to content

Commit 3a8ea32

Browse files
committed
Improve filtering test
1 parent 6e51eb6 commit 3a8ea32

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

perf-testing/immutability-benchmarks.mjs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ const add = index => ({
7474
payload: {id: index, value: index, nested: {data: index}}
7575
})
7676
const remove = index => ({type: "test/removeItem", payload: index})
77-
const filter = index => ({type: "test/filterItem", payload: index})
77+
const filter = percentToKeep => ({
78+
type: "test/filterItem",
79+
payload: percentToKeep
80+
})
7881
const update = index => ({
7982
type: "test/updateItem",
8083
payload: {id: index, value: index, nestedData: index}
@@ -155,8 +158,10 @@ const vanillaReducer = (state = createInitialState(), action) => {
155158
}
156159
}
157160
case "test/filterItem": {
161+
const keepPercentage = action.payload / 10
162+
const length = state.largeArray.length
158163
const newArray = state.largeArray.filter(
159-
(item, i) => i !== action.payload
164+
(item, i) => i / length < action.payload
160165
)
161166
return {
162167
...state,
@@ -202,8 +207,10 @@ const createImmerReducer = produce => {
202207
draft.largeArray.splice(action.payload, 1)
203208
break
204209
case "test/filterItem": {
210+
const keepPercentage = action.payload / 10
211+
const length = state.largeArray.length
205212
draft.largeArray = draft.largeArray.filter(
206-
(item, i) => i !== action.payload
213+
(item, i) => i / length < action.payload
207214
)
208215
break
209216
}

0 commit comments

Comments
 (0)