Skip to content

Commit 434b968

Browse files
committed
[CI][Perf] Fix sorting benchmark results files
Sort datetime objects instead of strings to get the proper result files list.
1 parent 97aba91 commit 434b968

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

devops/scripts/benchmarks/history.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ def load(self, n: int):
4040
benchmark_files = list(results_dir.glob("*.json"))
4141

4242
# Extract timestamp and sort files by it
43-
def extract_timestamp(file_path: Path) -> str:
43+
def extract_timestamp(file_path: Path) -> datetime:
4444
try:
4545
# Assumes results are stored as <name>_YYYYMMDD_HHMMSS.json
4646
ts = file_path.stem[-len("YYYYMMDD_HHMMSS") :]
47-
return ts if Validate.timestamp(ts) else ""
48-
except IndexError:
49-
return ""
47+
if Validate.timestamp(ts):
48+
return datetime.strptime(ts, "%Y%m%d_%H%M%S")
49+
return datetime.fromtimestamp(0) # Default to epoch if invalid
50+
except (IndexError, ValueError):
51+
return datetime.fromtimestamp(0) # Default to epoch if exception
5052

5153
benchmark_files.sort(key=extract_timestamp, reverse=True)
5254

0 commit comments

Comments
 (0)