33 InstrumentHooks ,
44 mongoMeasurement ,
55 optimizeFunction ,
6+ wrapWithRootFrame ,
7+ wrapWithRootFrameSync ,
68} from "@codspeed/core" ;
79import { Bench , Fn , FnOptions , Task } from "tinybench" ;
810import { BaseBenchRunner } from "./shared" ;
@@ -25,18 +27,6 @@ class AnalysisBenchRunner extends BaseBenchRunner {
2527 return InstrumentHooks . isInstrumented ( ) ? "Measured" : "Checked" ;
2628 }
2729
28- private wrapFunctionWithFrame ( fn : Fn , isAsync : boolean ) : Fn {
29- if ( isAsync ) {
30- return async function __codspeed_root_frame__ ( ) {
31- await fn ( ) ;
32- } ;
33- } else {
34- return function __codspeed_root_frame__ ( ) {
35- fn ( ) ;
36- } ;
37- }
38- }
39-
4030 protected async runTaskAsync ( task : Task , uri : string ) : Promise < void > {
4131 const { fnOpts, fn } = task as unknown as { fnOpts ?: FnOptions ; fn : Fn } ;
4232
@@ -50,10 +40,7 @@ class AnalysisBenchRunner extends BaseBenchRunner {
5040 await mongoMeasurement . start ( uri ) ;
5141
5242 global . gc ?.( ) ;
53- await this . wrapWithInstrumentHooksAsync (
54- this . wrapFunctionWithFrame ( fn , true ) ,
55- uri ,
56- ) ;
43+ await this . wrapWithInstrumentHooksAsync ( wrapWithRootFrame ( fn ) , uri ) ;
5744
5845 await mongoMeasurement . stop ( uri ) ;
5946 await fnOpts ?. afterEach ?. call ( task , "run" ) ;
@@ -68,7 +55,7 @@ class AnalysisBenchRunner extends BaseBenchRunner {
6855 fnOpts ?. beforeAll ?. call ( task , "run" ) ;
6956 fnOpts ?. beforeEach ?. call ( task , "run" ) ;
7057
71- this . wrapWithInstrumentHooks ( this . wrapFunctionWithFrame ( fn , false ) , uri ) ;
58+ this . wrapWithInstrumentHooks ( wrapWithRootFrameSync ( fn ) , uri ) ;
7259
7360 fnOpts ?. afterEach ?. call ( task , "run" ) ;
7461 fnOpts ?. afterAll ?. call ( task , "run" ) ;
0 commit comments