-
-
Notifications
You must be signed in to change notification settings - Fork 852
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmark for setUseStrictShallowCopy
- Loading branch information
hrsh7th
committed
May 19, 2022
1 parent
d693e8f
commit f9cdf8e
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {measure} from "./measure" | ||
import produce, { | ||
setUseProxies, | ||
setUseStrictShallowCopy, | ||
enableAllPlugins | ||
} from "../dist/immer.cjs.production.min.js" | ||
|
||
enableAllPlugins() | ||
|
||
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]++ | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters