Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than a52614a point at it.

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

lines 1–3why, one step back
1"use strict"
23import {measure} from "./measure"

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 4–8why, one step back
4import produce, {
5 setAutoFreeze,6 setUseProxies,7 enableAllPlugins8} from "../dist/immer.cjs.production.min.js"

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

lines 9–13why, one step back
9import cloneDeep from "lodash.clonedeep"
10import {fromJS} from "immutable"11import Seamless from "seamless-immutable"12import deepFreeze from "deep-freeze"13

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 14–15why, one step back
14enableAllPlugins()
15

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

lines 16–19why, one step back
16console.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 back
20 data: null

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

lines 21–26why, one step back
21}
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 back
27 "just mutate",
28 () => ({draft: cloneDeep(baseState)}),29 ({draft}) => {30 draft.data = dataSet31 }

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

lines 32–34why, one step back
32)
3334measure(

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 35–40why, one step back
35 "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 back
41)
4243measure("handcrafted reducer (no freeze)", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 44–47why, one step back
44 const nextState = {
45 ...baseState,46 data: dataSet47 }

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

lines 48–50why, one step back
48})
4950measure("handcrafted reducer (with freeze)", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 51–54why, one step back
51 const nextState = deepFreeze({
52 ...baseState,53 data: dataSet54 })

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

lines 55–57why, one step back
55})
5657measure("immutableJS", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 58–60why, one step back
58 let state = immutableJsBaseState.withMutations(state => {
59 state.setIn(["data"], fromJS(dataSet))60 })

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

lines 61–63why, one step back
61})
6263measure("immutableJS + toJS", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 64–68why, one step back
64 let state = immutableJsBaseState
65 .withMutations(state => {66 state.setIn(["data"], fromJS(dataSet))67 })68 .toJS()

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

lines 69–71why, one step back
69})
7071measure("seamless-immutable", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

line 72why, one step back
72 seamlessBaseState.set("data", dataSet)

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

lines 73–75why, one step back
73})
7475measure("seamless-immutable + asMutable", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

line 76why, one step back
76 seamlessBaseState.set("data", dataSet).asMutable({deep: true})

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

lines 77–79why, one step back
77})
7879measure("immer (proxy) - without autofreeze", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 80–84why, one step back
80 setUseProxies(true)
81 setAutoFreeze(false)82 produce(baseState, draft => {83 draft.data = dataSet84 })

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

lines 85–87why, one step back
85})
8687measure("immer (proxy) - with autofreeze", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 88–92why, one step back
88 setUseProxies(true)
89 setAutoFreeze(true)90 produce(frozenBazeState, draft => {91 draft.data = dataSet92 })

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

lines 93–95why, one step back
93})
9495measure("immer (es5) - without autofreeze", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 96–100why, one step back
96 setUseProxies(false)
97 setAutoFreeze(false)98 produce(baseState, draft => {99 draft.data = dataSet100 })

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

lines 101–103why, one step back
101})
102103measure("immer (es5) - with autofreeze", () => {

Fixed performance testsMichel Weststratebefore adoptionc2d7617

lines 104–108why, one step back
104 setUseProxies(false)
105 setAutoFreeze(true)106 produce(frozenBazeState, draft => {107 draft.data = dataSet108 })

test(ts): tiny improvementaleclarsonbefore adoptiona52614a

line 109why, one step back
109})