1- from utils .aggregate import SimpleMedian
1+ from utils .aggregate import Aggregator , SimpleMedian
22from utils .validate import Validate
33from utils .result import Result , BenchmarkRun
44from options import options
77import sys
88import json
99import argparse
10+ from datetime import datetime , timezone
1011from pathlib import Path
1112from dataclasses import dataclass , asdict
1213
@@ -106,7 +107,7 @@ def check_benchmark_result(result: BenchmarkRun) -> bool:
106107 if result .name != result_name :
107108 print (f"Warning: Result file { result_path } does not match specified result name { result .name } ." )
108109 return False
109- if result .date < datetime .strptime (cutoff , "%Y%m%d_%H%M%S" ):
110+ if result .date < datetime .strptime (cutoff , "%Y%m%d_%H%M%S" ). replace ( tzinfo = timezone . utc ) :
110111 return False
111112 return True
112113
@@ -183,6 +184,14 @@ def to_hist_avg(
183184 Returns:
184185 A tuple returning (list of improved tests, list of regressed tests).
185186 """
187+ def halfway_round (value : int , n : int ):
188+ """
189+ Python's default round() does banker's rounding, which doesn't
190+ make much sense here. This rounds 0.5 to 1, and -0.5 to -1
191+ """
192+ if value == 0 : return 0
193+ return int (value * 10 ** n + 0.5 * (value / abs (value ))) / 10 ** n
194+
186195 improvement = []
187196 regression = []
188197
@@ -206,9 +215,11 @@ def perf_diff_entry() -> dict:
206215 res ["avg_type" ] = hist_avg [test .name ].average_type
207216 return res
208217
209- if delta > options .regression_threshold :
218+ # Round to 2 decimal places: not going to fail a test on 0.001% over
219+ # regression threshold
220+ if halfway_round (delta , 2 ) > options .regression_threshold :
210221 improvement .append (perf_diff_entry ())
211- elif delta < - options .regression_threshold :
222+ elif halfway_round ( delta , 2 ) < - options .regression_threshold :
212223 regression .append (perf_diff_entry ())
213224
214225 return improvement , regression
0 commit comments