Skip to content

Commit 92f482a

Browse files
[Autoloop: perf-comparison] Iteration 379: add benchmark pair for add_sub_mul_div (arithmetic ops)
Run: https://github.com/githubnext/tsb/actions/runs/28343148408 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 717acd9 commit 92f482a

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Benchmark: Series.add/sub/mul/div — element-wise arithmetic."""
2+
import json
3+
import time
4+
5+
import pandas as pd
6+
7+
SIZE = 100_000
8+
WARMUP = 5
9+
ITERATIONS = 50
10+
11+
data = [float(i) for i in range(SIZE)]
12+
s = pd.Series(data)
13+
s2 = pd.Series([v * 2 for v in data])
14+
15+
for _ in range(WARMUP):
16+
s.add(10)
17+
s.sub(5)
18+
s.mul(3)
19+
s.div(2)
20+
s.add(s2)
21+
22+
times = []
23+
for _ in range(ITERATIONS):
24+
t0 = time.perf_counter()
25+
s.add(10)
26+
s.sub(5)
27+
s.mul(3)
28+
s.div(2)
29+
s.add(s2)
30+
times.append((time.perf_counter() - t0) * 1000)
31+
32+
total_ms = sum(times)
33+
print(
34+
json.dumps(
35+
{
36+
"function": "add_sub_mul_div",
37+
"mean_ms": round(total_ms / ITERATIONS, 3),
38+
"iterations": ITERATIONS,
39+
"total_ms": round(total_ms, 3),
40+
}
41+
)
42+
)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Benchmark: seriesAdd / seriesSub / seriesMul / seriesDiv — element-wise arithmetic.
3+
* Outputs JSON: {"function": "add_sub_mul_div", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { Series, seriesAdd, seriesSub, seriesMul, seriesDiv } from "../../src/index.ts";
6+
7+
const SIZE = 100_000;
8+
const WARMUP = 5;
9+
const ITERATIONS = 50;
10+
11+
const data = Array.from({ length: SIZE }, (_, i) => i * 1.0);
12+
const s = new Series({ data });
13+
const s2 = new Series({ data: data.map((v) => v * 2) });
14+
15+
for (let i = 0; i < WARMUP; i++) {
16+
seriesAdd(s, 10);
17+
seriesSub(s, 5);
18+
seriesMul(s, 3);
19+
seriesDiv(s, 2);
20+
seriesAdd(s, s2);
21+
}
22+
23+
const times: number[] = [];
24+
for (let i = 0; i < ITERATIONS; i++) {
25+
const start = performance.now();
26+
seriesAdd(s, 10);
27+
seriesSub(s, 5);
28+
seriesMul(s, 3);
29+
seriesDiv(s, 2);
30+
seriesAdd(s, s2);
31+
times.push(performance.now() - start);
32+
}
33+
34+
const totalMs = times.reduce((a, b) => a + b, 0);
35+
const meanMs = totalMs / ITERATIONS;
36+
console.log(
37+
JSON.stringify({
38+
function: "add_sub_mul_div",
39+
mean_ms: Math.round(meanMs * 1000) / 1000,
40+
iterations: ITERATIONS,
41+
total_ms: Math.round(totalMs * 1000) / 1000,
42+
}),
43+
);

0 commit comments

Comments
 (0)