From f9cdf8e6b468e5b35d37bfcb7c20ecce920a6012 Mon Sep 17 00:00:00 2001 From: hrsh7th <> Date: Fri, 20 May 2022 02:52:00 +0900 Subject: [PATCH] Add benchmark for setUseStrictShallowCopy --- __performance_tests__/large-obj.js | 62 ++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 __performance_tests__/large-obj.js diff --git a/__performance_tests__/large-obj.js b/__performance_tests__/large-obj.js new file mode 100644 index 000000000..df2475b91 --- /dev/null +++ b/__performance_tests__/large-obj.js @@ -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]++ + }) + } +}) diff --git a/package.json b/package.json index dda45b834..57bb7bbeb 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "sideEffects": false, "scripts": { "test": "jest && yarn test:build && yarn test:flow", - "test:perf": "cd __performance_tests__ && babel-node add-data.js && babel-node todo.js && babel-node incremental.js", + "test:perf": "cd __performance_tests__ && babel-node add-data.js && babel-node todo.js && babel-node incremental.js && babel-node large-obj.js", "test:flow": "yarn flow check __tests__/flow", "test:build": "yarn build && NODE_ENV='production' yarn jest --config jest.config.build.js", "watch": "jest --watch",