Skip to content
Myr

Add benchmark config

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Mark Erikson · committed by Mark Erikson · parent a0e11d9 · Browse files · 1 file+26 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+26 added−4 removed

  • other:+26 added−4 removed

1 file+26 added−4 removed

modified:perf-testing/immutability-benchmarks.mjs+26 added-4 removed
24 unmodified lines
25} from "structurajs"26import {produce as produceLimu, setAutoFreeze as setAutoFreezeLimu} from "limu"27import {bench, run, group, summary} from "mitata"2829function createInitialState() {29function createInitialState(arraySize = BENCHMARK_CONFIG.arraySize) {30 const initialState = {31 largeArray: Array.from({length: 10000}, (_, i) => ({31 largeArray: Array.from({length: arraySize}, (_, i) => ({32 id: i,33 value: Math.random(),34 nested: {key: `key-${i}`, data: Math.random()},35 moreNested: {36 items: Array.from({length: 100}, (_, i) => ({id: i, name: String(i)}))36 items: Array.from(37 {length: BENCHMARK_CONFIG.nestedArraySize},38 (_, i) => ({id: i, name: String(i)})39 )40 }41 })),39 otherData: Array.from({length: 10000}, (_, i) => ({42 otherData: Array.from({length: arraySize}, (_, i) => ({43 id: i,44 name: `name-${i}`,45 isActive: i % 2 === 046 }))
2 unmodified lines
49}5051const MAX = 15253const BENCHMARK_CONFIG = {54 iterations: 1,55 arraySize: 10000,56 nestedArraySize: 100,57 multiUpdateCount: 5,58 reuseStateIterations: 1059}6061// Utility functions for calculating array indices based on size62const getValidIndex = (arraySize = BENCHMARK_CONFIG.arraySize) => {63 // Return a valid index (not the last one to avoid edge cases)64 return Math.min(arraySize - 2, Math.max(0, arraySize - 2))65}6667const getValidId = (arraySize = BENCHMARK_CONFIG.arraySize) => {68 // Return a valid ID that exists in the array69 return Math.min(arraySize - 2, Math.max(0, arraySize - 2))70}7172const add = index => ({73 type: "test/addItem",74 payload: {id: index, value: index, nested: {data: index}}75})
204 unmodified lines