add-data.js
This file
Path
__performance_tests__/add-data.js
109 lines · 2.2 KiB · JavaScript
Last changed by
Fixed performance testsMichel Weststratebefore adoptionc2d7617
History of this fileTake it
The walk stopped after 200 commits: lines older than a52614a point at it.
test(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 1–3why, one step back1"use strict"23import {measure} from "./measure"Fixed performance testsMichel Weststratebefore adoptionc2d7617
lines 4–8why, one step back4import produce, {5 setAutoFreeze,6 setUseProxies,7 enableAllPlugins8} from "../dist/immer.cjs.production.min.js"test(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 9–13why, one step back9import cloneDeep from "lodash.clonedeep"10import {fromJS} from "immutable"11import Seamless from "seamless-immutable"12import deepFreeze from "deep-freeze"13Fixed performance testsMichel Weststratebefore adoptionc2d7617
lines 14–15why, one step back14enableAllPlugins()15test(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 16–19why, one step back16console.log("\n# add-data - loading large set of data\n")1718const dataSet = require("./data.json")19const baseState = {Fixed performance testsMichel Weststratebefore adoptionc2d7617
line 20why, one step back20 data: nulltest(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 21–26why, one step back21}22const frozenBazeState = deepFreeze(cloneDeep(baseState))23const immutableJsBaseState = fromJS(baseState)24const seamlessBaseState = Seamless.from(baseState)2526measure(Fixed performance testsMichel Weststratebefore adoptionc2d7617
lines 27–31why, one step back27 "just mutate",28 () => ({draft: cloneDeep(baseState)}),29 ({draft}) => {30 draft.data = dataSet31 }test(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 32–34why, one step back32)3334measure(Fixed performance testsMichel Weststratebefore adoptionc2d7617
lines 35–40why, one step back35 "just mutate, freeze",36 () => ({draft: cloneDeep(baseState)}),37 ({draft}) => {38 draft.data = dataSet39 deepFreeze(draft)40 }test(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 41–43why, one step back41)4243measure("handcrafted reducer (no freeze)", () => {Fixed performance testsMichel Weststratebefore adoptionc2d7617
lines 44–47why, one step back44 const nextState = {45 ...baseState,46 data: dataSet47 }test(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 48–50why, one step back48})4950measure("handcrafted reducer (with freeze)", () => {Fixed performance testsMichel Weststratebefore adoptionc2d7617
lines 51–54why, one step back51 const nextState = deepFreeze({52 ...baseState,53 data: dataSet54 })test(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 55–57why, one step back55})5657measure("immutableJS", () => {Fixed performance testsMichel Weststratebefore adoptionc2d7617
lines 58–60why, one step back58 let state = immutableJsBaseState.withMutations(state => {59 state.setIn(["data"], fromJS(dataSet))60 })test(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 61–63why, one step back61})6263measure("immutableJS + toJS", () => {Fixed performance testsMichel Weststratebefore adoptionc2d7617
lines 64–68why, one step back64 let state = immutableJsBaseState65 .withMutations(state => {66 state.setIn(["data"], fromJS(dataSet))67 })68 .toJS()test(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 69–71why, one step back69})7071measure("seamless-immutable", () => {Fixed performance testsMichel Weststratebefore adoptionc2d7617
line 72why, one step back72 seamlessBaseState.set("data", dataSet)test(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 73–75why, one step back73})7475measure("seamless-immutable + asMutable", () => {Fixed performance testsMichel Weststratebefore adoptionc2d7617
line 76why, one step back76 seamlessBaseState.set("data", dataSet).asMutable({deep: true})test(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 77–79why, one step back77})7879measure("immer (proxy) - without autofreeze", () => {Fixed performance testsMichel Weststratebefore adoptionc2d7617
lines 80–84why, one step back80 setUseProxies(true)81 setAutoFreeze(false)82 produce(baseState, draft => {83 draft.data = dataSet84 })test(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 85–87why, one step back85})8687measure("immer (proxy) - with autofreeze", () => {Fixed performance testsMichel Weststratebefore adoptionc2d7617
lines 88–92why, one step back88 setUseProxies(true)89 setAutoFreeze(true)90 produce(frozenBazeState, draft => {91 draft.data = dataSet92 })test(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 93–95why, one step back93})9495measure("immer (es5) - without autofreeze", () => {Fixed performance testsMichel Weststratebefore adoptionc2d7617
lines 96–100why, one step back96 setUseProxies(false)97 setAutoFreeze(false)98 produce(baseState, draft => {99 draft.data = dataSet100 })test(ts): tiny improvementaleclarsonbefore adoptiona52614a
lines 101–103why, one step back101})102103measure("immer (es5) - with autofreeze", () => {Fixed performance testsMichel Weststratebefore adoptionc2d7617
lines 104–108why, one step back104 setUseProxies(false)105 setAutoFreeze(true)106 produce(frozenBazeState, draft => {107 draft.data = dataSet108 })test(ts): tiny improvementaleclarsonbefore adoptiona52614a
line 109why, one step back109})