add-data.js
This file
Path
__performance_tests__/add-data.js
103 lines · 2.3 KiB · JavaScript
Last changed by
Update readmeMichel Weststratebefore adoption341cfeb
History of this fileTake it
Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
lines 1–2why, one step back1"use strict"2Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
line 3why, one step back3import {measure} from "./measure"Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
lines 4–6why, one step back4import produce, {setAutoFreeze, setUseProxies} from "../dist/immer.umd.js"5import cloneDeep from "lodash.clonedeep"6import {fromJS} from "immutable"Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
line 7why, one step back7import Seamless from "seamless-immutable"Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
lines 8–9why, one step back8import deepFreeze from "deep-freeze"9Update readmeMichel Weststratebefore adoption341cfeb
line 10why, one step back10console.log("\n# add-data - loading large set of data\n")Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 11why, one step back11Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
lines 12–24why, one step back12const dataSet = require("./data.json")13const baseState = {14 data: null15}16const frozenBazeState = deepFreeze(cloneDeep(baseState))17const immutableJsBaseState = fromJS(baseState)18const seamlessBaseState = Seamless.from(baseState)1920measure(21 "just mutate",22 () => ({draft: cloneDeep(baseState)}),23 ({draft}) => {24 draft.data = dataSetMerge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 25why, one step back25 }Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
line 26why, one step back26)Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 27why, one step back27Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
lines 28–33why, one step back28measure(29 "just mutate, freeze",30 () => ({draft: cloneDeep(baseState)}),31 ({draft}) => {32 draft.data = dataSet33 deepFreeze(draft)Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 34why, one step back34 }Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
line 35why, one step back35)Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 36why, one step back36Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
lines 37–40why, one step back37measure("handcrafted reducer (no freeze)", () => {38 const nextState = {39 ...baseState,40 data: dataSetMerge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 41why, one step back41 }Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
line 42why, one step back42})Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 43why, one step back43Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
lines 44–47why, one step back44measure("handcrafted reducer (with freeze)", () => {45 const nextState = deepFreeze({46 ...baseState,47 data: dataSetMerge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 48why, one step back48 })Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
line 49why, one step back49})Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 50why, one step back50Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
lines 51–53why, one step back51measure("immutableJS", () => {52 let state = immutableJsBaseState.withMutations(state => {53 state.setIn(["data"], fromJS(dataSet))Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 54why, one step back54 })Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
line 55why, one step back55})Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 56why, one step back56Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
lines 57–59why, one step back57measure("immutableJS + toJS", () => {58 let state = immutableJsBaseState59 .withMutations(state => {Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
lines 60–61why, one step back60 state.setIn(["data"], fromJS(dataSet))61 })Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
lines 62–63why, one step back62 .toJS()63})Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 64why, one step back64Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
lines 65–67why, one step back65measure("seamless-immutable", () => {66 seamlessBaseState.set("data", dataSet)67})Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 68why, one step back68Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
lines 69–77why, one step back69measure("seamless-immutable + asMutable", () => {70 seamlessBaseState.set("data", dataSet).asMutable({deep: true})71})7273measure("immer (proxy) - without autofreeze", () => {74 setUseProxies(true)75 setAutoFreeze(false)76 produce(baseState, draft => {77 draft.data = dataSetMerge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 78why, one step back78 })Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
line 79why, one step back79})Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 80why, one step back80Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
lines 81–85why, one step back81measure("immer (proxy) - with autofreeze", () => {82 setUseProxies(true)83 setAutoFreeze(true)84 produce(frozenBazeState, draft => {85 draft.data = dataSetMerge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 86why, one step back86 })Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
line 87why, one step back87})Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 88why, one step back88Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
lines 89–93why, one step back89measure("immer (es5) - without autofreeze", () => {90 setUseProxies(false)91 setAutoFreeze(false)92 produce(baseState, draft => {93 draft.data = dataSetMerge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 94why, one step back94 })Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
line 95why, one step back95})Merge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
line 96why, one step back96Merge branch 'pekeler-seamless-immutable'Michel Weststratebefore adoption6e23240
lines 97–101why, one step back97measure("immer (es5) - with autofreeze", () => {98 setUseProxies(false)99 setAutoFreeze(true)100 produce(frozenBazeState, draft => {101 draft.data = dataSetMerge pull request #69 from mweststrate/feature/fast-pruneMichel Weststratebefore adoptione28bf2a
lines 102–103why, one step back102 })103})