import { bench, describe, beforeEach } from 'vitest'; import { ActionMap, createActionMap } from '../src/action-map'; import { IAction, actionCreator } from '../src/action'; // Make sure this is the original imported actionCreator // Helper to generate many actions using the imported actionCreator function generateActions(count: number) { const actions = []; for (let i = 0; i < count; i++) { const AC = actionCreator(`action${i}`); actions.push(AC('payload')); } return actions; } const ACTION_COUNT = 100; function count(max: number = ACTION_COUNT) { return Math.floor(Math.random() * max); } describe('ActionMap creation performance', () => { let actions: IAction[] = []; let map: ActionMap; beforeEach(() => { actions = generateActions(count()); }); bench('new ActionMap(actions)', () => { map = new ActionMap(actions.slice(0, count(actions.length - 1))); }); bench('createActionMap(...actions.slice(0, actions.length - 1))', () => { map = createActionMap(...actions.slice(0, count(actions.length - 1))); }); });