Skip to content

Commit a025b6b

Browse files
[Autoloop: perf-comparison] Iteration 413: add readHdf/toHdf benchmark pair
Run: https://github.com/githubnext/tsb/actions/runs/29792948080 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9ce9573 commit a025b6b

2 files changed

Lines changed: 80 additions & 0 deletions

File tree

benchmarks/pandas/bench_readHdf.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Benchmark: read_hdf / to_hdf — HDF5 round-trip on a 10k-row DataFrame"""
2+
import json, time, io
3+
import numpy as np
4+
import pandas as pd
5+
6+
ROWS = 10_000
7+
WARMUP = 3
8+
ITERATIONS = 20
9+
10+
rng = np.arange(ROWS)
11+
df = pd.DataFrame({
12+
"id": rng,
13+
"value": rng * 1.23456,
14+
"flag": rng % 2,
15+
})
16+
17+
tmp_path = "/tmp/gh-aw/agent/bench_readHdf.h5"
18+
19+
def roundtrip():
20+
df.to_hdf(tmp_path, key="df", mode="w")
21+
pd.read_hdf(tmp_path, key="df")
22+
23+
for _ in range(WARMUP):
24+
roundtrip()
25+
26+
start = time.perf_counter()
27+
for _ in range(ITERATIONS):
28+
roundtrip()
29+
total = (time.perf_counter() - start) * 1000
30+
31+
print(json.dumps({
32+
"function": "readHdf",
33+
"mean_ms": total / ITERATIONS,
34+
"iterations": ITERATIONS,
35+
"total_ms": total,
36+
}))

benchmarks/tsb/bench_readHdf.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Benchmark: readHdf / toHdf — HDF5 round-trip on a 10k-row DataFrame
3+
*/
4+
import { DataFrame } from "../../src/index.js";
5+
import { readHdf, toHdf } from "../../src/index.js";
6+
7+
const ROWS = 10_000;
8+
const WARMUP = 3;
9+
const ITERATIONS = 20;
10+
11+
// Build a DataFrame with mixed numeric and string columns
12+
const ids = new Array<number>(ROWS).fill(0).map((_, i) => i);
13+
const values = new Array<number>(ROWS).fill(0).map((_, i) => i * 1.23456);
14+
const flags = new Array<number>(ROWS).fill(0).map((_, i) => i % 2);
15+
16+
const df = DataFrame.fromColumns({
17+
id: ids,
18+
value: values,
19+
flag: flags,
20+
});
21+
22+
// Pre-serialise once so both readHdf and toHdf are benchmarked together
23+
const buf = toHdf(df);
24+
25+
for (let i = 0; i < WARMUP; i++) {
26+
const out = toHdf(df);
27+
readHdf(out);
28+
}
29+
30+
const start = performance.now();
31+
for (let i = 0; i < ITERATIONS; i++) {
32+
const out = toHdf(df);
33+
readHdf(out);
34+
}
35+
const total = performance.now() - start;
36+
37+
console.log(
38+
JSON.stringify({
39+
function: "readHdf",
40+
mean_ms: total / ITERATIONS,
41+
iterations: ITERATIONS,
42+
total_ms: total,
43+
}),
44+
);

0 commit comments

Comments
 (0)