import {itBench} from "@dapplion/benchmark";
import {beforeProcessEpoch} from "../../../src/index.js";
import {StateEpoch} from "../types.js";
import {generatePerfTestCachedStatePhase0, perfStateId} from "../util.js";

// PERF: Cost = compute attester and proposer shufflings ~ 'proportional' to $VALIDATOR_COUNT, but independent of
// network conditions. See also individual benchmarks for shuffling computations.

describe("phase0 afterProcessEpoch", () => {
  itBench<StateEpoch, StateEpoch>({
    id: `phase0 afterProcessEpoch - ${perfStateId}`,
    yieldEventLoopAfterEach: true, // So SubTree(s)'s WeakRef can be garbage collected https://github.com/nodejs/node/issues/39902
    before: () => {
      const state = generatePerfTestCachedStatePhase0({goBackOneSlot: true});
      const cache = beforeProcessEpoch(state);
      return {state: state, cache};
    },
    beforeEach: ({state, cache}) => ({state: state.clone(), cache}),
    fn: ({state, cache}) => {
      state.epochCtx.afterProcessEpoch(state, cache);
    },
  });
});
