Skip to content

Commit 9bd519f

Browse files
committed
Ensure timezones are UTC
1 parent 4f5ce71 commit 9bd519f

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

devops/scripts/benchmarks/compare.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from utils.aggregate import SimpleMedian
1+
from utils.aggregate import Aggregator, SimpleMedian
22
from utils.validate import Validate
33
from utils.result import Result, BenchmarkRun
44
from options import options
@@ -7,6 +7,7 @@
77
import sys
88
import json
99
import argparse
10+
from datetime import datetime, timezone
1011
from pathlib import Path
1112
from 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

devops/scripts/benchmarks/history.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def save(self, save_name, results: list[Result], to_file=True):
120120

121121
# Use formatted timestamp for the filename
122122
timestamp = (
123-
datetime.now().strftime("%Y%m%d_%H%M%S")
123+
datetime.now(tz=timezone.utc).strftime("%Y%m%d_%H%M%S")
124124
if options.timestamp_override is None else
125125
options.timestamp_override
126126
)

0 commit comments

Comments
 (0)