Skip to content

Commit

Permalink
Add large object perf test (from #941)
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Mar 24, 2023
2 parents 6e9032b + da3de76 commit d533f24
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions __performance_tests__/large-obj.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {measure} from "./measure"
import {
produce,
setUseProxies,
setUseStrictShallowCopy
} from "../dist/immer.cjs.production.min.js"

console.log("\n# large-obj - mutate large object\n")

const MAX = 50

const baseState = Object.fromEntries(
Array(10000)
.fill(0)
.map((_, i) => [i, i])
)

measure("immer (proxy) - with setUseStrictShallowCopy", () => {
setUseStrictShallowCopy(true)
setUseProxies(true)

for (let i = 0; i < MAX; i++) {
produce(baseState, draft => {
draft[5000]++
})
}
})

measure("immer (proxy) - without setUseStrictShallowCopy", () => {
setUseStrictShallowCopy(false)
setUseProxies(true)

for (let i = 0; i < MAX; i++) {
produce(baseState, draft => {
draft[5000]++
})
}
})

measure("immer (es5) - with setUseStrictShallowCopy", () => {
setUseStrictShallowCopy(true)
setUseProxies(false)

for (let i = 0; i < MAX; i++) {
produce(baseState, draft => {
draft[5000]++
})
}
})

measure("immer (es5) - without setUseStrictShallowCopy", () => {
setUseStrictShallowCopy(false)
setUseProxies(false)

for (let i = 0; i < MAX; i++) {
produce(baseState, draft => {
draft[5000]++
})
}
})

0 comments on commit d533f24

Please sign in to comment.