Skip to content

Commit d95bec2

Browse files
[Autoloop: perf-comparison] Iteration 407: add toExcel benchmark pair
Run: https://github.com/githubnext/tsb/actions/runs/29625071540 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 36f244d commit d95bec2

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Benchmark: to_excel — write a DataFrame to an XLSX buffer (BytesIO)."""
2+
import json, time, io
3+
import pandas as pd
4+
5+
ROWS = 5_000
6+
WARMUP = 3
7+
ITERATIONS = 20
8+
9+
df = pd.DataFrame({
10+
"name": [f"name_{i % 1000}" for i in range(ROWS)],
11+
"value": [i * 1.5 for i in range(ROWS)],
12+
"flag": [i % 2 == 0 for i in range(ROWS)],
13+
})
14+
15+
for _ in range(WARMUP):
16+
buf = io.BytesIO()
17+
df.to_excel(buf, index=True)
18+
19+
times = []
20+
for _ in range(ITERATIONS):
21+
buf = io.BytesIO()
22+
t0 = time.perf_counter()
23+
df.to_excel(buf, index=True)
24+
times.append((time.perf_counter() - t0) * 1000)
25+
26+
total_ms = sum(times)
27+
print(json.dumps({"function": "to_excel", "mean_ms": round(total_ms / ITERATIONS, 3), "iterations": ITERATIONS, "total_ms": round(total_ms, 3)}))

benchmarks/tsb/bench_to_excel.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Benchmark: toExcel — serialize a DataFrame to an XLSX binary buffer.
3+
* Outputs JSON: {"function": "to_excel", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { DataFrame, toExcel } from "../../src/index.ts";
6+
7+
const ROWS = 5_000;
8+
const WARMUP = 3;
9+
const ITERATIONS = 20;
10+
11+
const index = Array.from({ length: ROWS }, (_, i) => i);
12+
const colA = Array.from({ length: ROWS }, (_, i) => `name_${i % 1000}`);
13+
const colB = Array.from({ length: ROWS }, (_, i) => i * 1.5);
14+
const colC = Array.from({ length: ROWS }, (_, i) => i % 2 === 0);
15+
16+
const df = new DataFrame({ name: colA, value: colB, flag: colC }, { index });
17+
18+
for (let i = 0; i < WARMUP; i++) {
19+
toExcel(df);
20+
}
21+
22+
const times: number[] = [];
23+
for (let i = 0; i < ITERATIONS; i++) {
24+
const start = performance.now();
25+
toExcel(df);
26+
times.push(performance.now() - start);
27+
}
28+
29+
const totalMs = times.reduce((a, b) => a + b, 0);
30+
const meanMs = totalMs / ITERATIONS;
31+
console.log(
32+
JSON.stringify({
33+
function: "to_excel",
34+
mean_ms: Math.round(meanMs * 1000) / 1000,
35+
iterations: ITERATIONS,
36+
total_ms: Math.round(totalMs * 1000) / 1000,
37+
}),
38+
);

0 commit comments

Comments
 (0)