@@ -32,6 +32,11 @@ export interface BenchFixtures {
3232 */
3333export type BenchFunction = ( fixtures : BenchFixtures ) => void | Promise < void > ;
3434
35+ /**
36+ * A hook run around the measured region. Not included in the reported timing.
37+ */
38+ export type BenchHook = ( fixtures : BenchFixtures ) => void | Promise < void > ;
39+
3540/**
3641 * Minimal options for a benchmark. Inspired by Vitest's `bench`, but kept
3742 * deliberately small.
@@ -61,6 +66,16 @@ export interface BenchOptions {
6166 * directory.
6267 */
6368 executablePath ?: string ;
69+ /**
70+ * Run before each round, after the window opens. Use it to bring the app to
71+ * a steady state (initial render done, data loaded, …). Not measured.
72+ */
73+ setup ?: BenchHook ;
74+ /**
75+ * Run after each round, before the app is closed. Use it for teardown that
76+ * should not be measured.
77+ */
78+ teardown ?: BenchHook ;
6479}
6580
6681let integrationInitialized = false ;
@@ -111,6 +126,10 @@ async function runOneSample(
111126 const page = await app . firstWindow ( ) ;
112127
113128 try {
129+ if ( options . setup ) {
130+ await options . setup ( { page } ) ;
131+ }
132+
114133 const startTs = InstrumentHooks . currentTimestamp ( ) ;
115134 await fn ( { page } ) ;
116135 const endTs = InstrumentHooks . currentTimestamp ( ) ;
@@ -122,6 +141,10 @@ async function runOneSample(
122141 ) ;
123142 InstrumentHooks . addMarker ( process . pid , MARKER_TYPE_BENCHMARK_END , endTs ) ;
124143
144+ if ( options . teardown ) {
145+ await options . teardown ( { page } ) ;
146+ }
147+
125148 return endTs - startTs ;
126149 } finally {
127150 await app . close ( ) ;
0 commit comments