@@ -183,7 +183,7 @@ def get_instrument_config_str_and_warns(self) -> tuple[str, list[str]]:
183183 )
184184 return config_str , []
185185
186- def measure (
186+ def measure ( # noqa: C901
187187 self ,
188188 marker_options : BenchmarkMarkerOptions ,
189189 name : str ,
@@ -232,21 +232,31 @@ def __codspeed_root_frame__() -> T:
232232 # Benchmark
233233 iter_range = range (iter_per_round )
234234 run_start = perf_counter_ns ()
235- if self .instrument_hooks :
236- self .instrument_hooks .start_benchmark ()
235+ hooks = self .instrument_hooks
236+ if hooks :
237+ hooks .start_benchmark ()
237238 for _ in range (rounds ):
239+ instrument_hooks_start = hooks .current_timestamp () if hooks else None
238240 start = perf_counter_ns ()
241+
239242 for _ in iter_range :
240243 __codspeed_root_frame__ ()
244+
241245 end = perf_counter_ns ()
246+ if hooks and instrument_hooks_start is not None :
247+ instrument_hooks_end = hooks .current_timestamp ()
248+ hooks .add_benchmark_timestamps (
249+ instrument_hooks_start , instrument_hooks_end
250+ )
251+
242252 times_per_round_ns .append (end - start )
243253
244254 if end - run_start > benchmark_config .max_time_ns :
245255 # TODO: log something
246256 break
247- if self . instrument_hooks :
248- self . instrument_hooks .stop_benchmark ()
249- self . instrument_hooks .set_executed_benchmark (uri )
257+ if hooks :
258+ hooks .stop_benchmark ()
259+ hooks .set_executed_benchmark (uri )
250260 benchmark_end = perf_counter_ns ()
251261 total_time = (benchmark_end - run_start ) / 1e9
252262
@@ -290,20 +300,30 @@ def __codspeed_root_frame__(*args, **kwargs) -> T:
290300 # Benchmark
291301 times_per_round_ns : list [float ] = []
292302 benchmark_start = perf_counter_ns ()
293- if self .instrument_hooks :
294- self .instrument_hooks .start_benchmark ()
303+ hooks = self .instrument_hooks
304+ if hooks :
305+ hooks .start_benchmark ()
295306 for _ in range (pedantic_options .rounds ):
296307 args , kwargs = pedantic_options .setup_and_get_args_kwargs ()
308+ instrument_hooks_start = hooks .current_timestamp () if hooks else None
297309 start = perf_counter_ns ()
310+
298311 for _ in iter_range :
299312 __codspeed_root_frame__ (* args , ** kwargs )
313+
300314 end = perf_counter_ns ()
315+ if hooks and instrument_hooks_start is not None :
316+ instrument_hooks_end = hooks .current_timestamp ()
317+ hooks .add_benchmark_timestamps (
318+ instrument_hooks_start , instrument_hooks_end
319+ )
320+
301321 times_per_round_ns .append (end - start )
302322 if pedantic_options .teardown is not None :
303323 pedantic_options .teardown (* args , ** kwargs )
304- if self . instrument_hooks :
305- self . instrument_hooks .stop_benchmark ()
306- self . instrument_hooks .set_executed_benchmark (uri )
324+ if hooks :
325+ hooks .stop_benchmark ()
326+ hooks .set_executed_benchmark (uri )
307327 benchmark_end = perf_counter_ns ()
308328 total_time = (benchmark_end - benchmark_start ) / 1e9
309329 stats = BenchmarkStats .from_list (
0 commit comments