Skip to content

Commit 38a4f65

Browse files
Copilotmrjf
andauthored
Improve benchmark runner error handling and Python compatibility
- Add error handling for malformed JSON in benchmark output parsing - Fix division-by-zero edge case in ratio calculation - Use string-quoted type hints in Python for broader compatibility Agent-Logs-Url: https://github.com/githubnext/tsessebe/sessions/4b3aa7c2-4060-4c79-b63c-1717b2502bb1 Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
1 parent 5e43c3d commit 38a4f65

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

benchmarks/pandas/bench_series_creation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ITERATIONS = 50
1616

1717

18-
def generate_data(n: int) -> list[float]:
18+
def generate_data(n: int) -> "list[float]":
1919
"""Generate a deterministic numeric array of the given size."""
2020
return [i * 1.1 + 0.5 for i in range(n)]
2121

@@ -27,7 +27,7 @@ def generate_data(n: int) -> list[float]:
2727
pd.Series(list(data))
2828

2929
# Measured runs
30-
times: list[float] = []
30+
times: "list[float]" = []
3131
for _ in range(ITERATIONS):
3232
start = time.perf_counter()
3333
pd.Series(list(data))

benchmarks/results.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
{
2-
"benchmarks": [],
3-
"timestamp": null
4-
}
1+
{"benchmarks": [], "timestamp": null}

benchmarks/run_benchmarks.sh

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,27 @@ for ts_bench in "$SCRIPT_DIR"/tsb/bench_*.ts; do
6565
echo " pandas result: $py_result"
6666

6767
# Extract mean_ms from both
68-
ts_mean=$(echo "$ts_result" | python3 -c "import sys, json; print(json.load(sys.stdin)['mean_ms'])")
69-
py_mean=$(echo "$py_result" | python3 -c "import sys, json; print(json.load(sys.stdin)['mean_ms'])")
68+
ts_mean=$(echo "$ts_result" | python3 -c "import sys, json; d=json.load(sys.stdin); print(d['mean_ms'])" 2>/dev/null) || {
69+
echo " ERROR: could not parse tsb benchmark result"
70+
continue
71+
}
72+
py_mean=$(echo "$py_result" | python3 -c "import sys, json; d=json.load(sys.stdin); print(d['mean_ms'])" 2>/dev/null) || {
73+
echo " ERROR: could not parse pandas benchmark result"
74+
continue
75+
}
7076

7177
# Calculate ratio (tsb / pandas) — < 1.0 means tsb is faster
72-
ratio=$(python3 -c "print(round($ts_mean / $py_mean if $py_mean > 0 else 0, 3))")
78+
ratio=$(python3 -c "
79+
ts, py = $ts_mean, $py_mean
80+
if py <= 0:
81+
print('null')
82+
else:
83+
print(round(ts / py, 3))
84+
")
85+
if [ "$ratio" = "null" ]; then
86+
echo " ERROR: pandas mean_ms is zero, cannot compute ratio"
87+
continue
88+
fi
7389

7490
echo " Ratio (tsb/pandas): ${ratio}x"
7591
echo ""

0 commit comments

Comments
 (0)