11from __future__ import annotations
22
3+ import logging
34import shutil
5+ from operator import itemgetter
46from typing import TYPE_CHECKING , Optional
57
68from rich .console import Console
@@ -19,24 +21,27 @@ def validate_and_format_benchmark_table(
1921 function_benchmark_timings : dict [str , dict [BenchmarkKey , float ]], total_benchmark_timings : dict [BenchmarkKey , float ]
2022) -> dict [str , list [tuple [BenchmarkKey , float , float , float ]]]:
2123 function_to_result = {}
22- # Process each function's benchmark data
24+ scale = 1_000_000.0
2325 for func_path , test_times in function_benchmark_timings .items ():
2426 # Sort by percentage (highest first)
2527 sorted_tests = []
2628 for benchmark_key , func_time in test_times .items ():
2729 total_time = total_benchmark_timings .get (benchmark_key , 0 )
2830 if func_time > total_time :
29- logger .debug (f"Skipping test { benchmark_key } due to func_time { func_time } > total_time { total_time } " )
3031 # If the function time is greater than total time, likely to have multithreading / multiprocessing issues.
3132 # Do not try to project the optimization impact for this function.
33+ if logger .isEnabledFor (logging .DEBUG ):
34+ logger .debug (
35+ f"Skipping test { benchmark_key } due to func_time { func_time } > total_time { total_time } "
36+ )
3237 sorted_tests .append ((benchmark_key , 0.0 , 0.0 , 0.0 ))
3338 elif total_time > 0 :
3439 percentage = (func_time / total_time ) * 100
3540 # Convert nanoseconds to milliseconds
36- func_time_ms = func_time / 1_000_000
37- total_time_ms = total_time / 1_000_000
41+ func_time_ms = func_time / scale
42+ total_time_ms = total_time / scale
3843 sorted_tests .append ((benchmark_key , total_time_ms , func_time_ms , percentage ))
39- sorted_tests .sort (key = lambda x : x [ 3 ] , reverse = True )
44+ sorted_tests .sort (key = itemgetter ( 3 ) , reverse = True )
4045 function_to_result [func_path ] = sorted_tests
4146 return function_to_result
4247
0 commit comments