@@ -63,4 +63,55 @@ export function runInstrumentedBench(
6363 console . log ( `[CodSpeed] Done running ${ bench . tasks . length } benches.` ) ;
6464 return bench . tasks ;
6565 } ;
66+
67+ bench . runSync = ( ) => {
68+ console . log (
69+ `[CodSpeed] running with @codspeed/tinybench v${ __VERSION__ } (instrumented mode)`
70+ ) ;
71+
72+ for ( const task of bench . tasks ) {
73+ const uri = getTaskUri ( bench , task . name , rootCallingFile ) ;
74+
75+ // Access private fields
76+ const { fnOpts, fn } = task as unknown as { fnOpts ?: FnOptions ; fn : Fn } ;
77+
78+ // Call beforeAll hook if it exists
79+ fnOpts ?. beforeAll ?. call ( task , "run" ) ;
80+
81+ // run optimizations
82+ optimizeFunction ( async ( ) => {
83+ fnOpts ?. beforeEach ?. call ( task , "run" ) ;
84+ fn ( ) ;
85+ fnOpts ?. afterEach ?. call ( task , "run" ) ;
86+ } ) ;
87+
88+ // run instrumented benchmark
89+ fnOpts ?. beforeEach ?. call ( task , "run" ) ;
90+
91+ // await mongoMeasurement.start(uri);
92+ global . gc ?.( ) ;
93+ ( function __codspeed_root_frame__ ( ) {
94+ InstrumentHooks . startBenchmark ( ) ;
95+ fn ( ) ;
96+ InstrumentHooks . stopBenchmark ( ) ;
97+ InstrumentHooks . setExecutedBenchmark ( process . pid , uri ) ;
98+ } ) ( ) ;
99+ mongoMeasurement . stop ( uri ) ;
100+
101+ fnOpts ?. afterEach ?. call ( task , "run" ) ;
102+
103+ fnOpts ?. afterAll ?. call ( task , "run" ) ;
104+
105+ // print results
106+ console . log (
107+ ` ✔ ${
108+ InstrumentHooks . isInstrumented ( ) ? "Measured" : "Checked"
109+ } ${ uri } `
110+ ) ;
111+ }
112+
113+ teardownCore ( ) ;
114+ console . log ( `[CodSpeed] Done running ${ bench . tasks . length } benches.` ) ;
115+ return bench . tasks ;
116+ } ;
66117}
0 commit comments