Skip to content

Commit abf504e

Browse files
authored
Merge pull request #322 from githubnext/autoloop/perf-comparison
[Autoloop: perf-comparison]
2 parents 4ccf956 + d36e8fa commit abf504e

4 files changed

Lines changed: 142 additions & 0 deletions

File tree

benchmarks/pandas/bench_combine.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Benchmark: Series.combine / DataFrame.combine — element-wise binary combine."""
2+
import json
3+
import time
4+
import pandas as pd
5+
import numpy as np
6+
7+
SIZE = 10_000
8+
WARMUP = 5
9+
ITERATIONS = 100
10+
11+
a = pd.Series(range(SIZE))
12+
b = pd.Series(range(SIZE, 0, -1))
13+
14+
df_a = pd.DataFrame({"x": range(SIZE), "y": [i * 2 for i in range(SIZE)]})
15+
df_b = pd.DataFrame({"x": range(SIZE, 0, -1), "z": [i * 3 for i in range(SIZE)]})
16+
17+
add_fn = lambda p, q: p + q
18+
19+
for _ in range(WARMUP):
20+
a.combine(b, add_fn, fill_value=0)
21+
df_a.combine(df_b, add_fn, fill_value=0)
22+
23+
start = time.perf_counter()
24+
for _ in range(ITERATIONS):
25+
a.combine(b, add_fn, fill_value=0)
26+
df_a.combine(df_b, add_fn, fill_value=0)
27+
total = (time.perf_counter() - start) * 1000
28+
29+
print(json.dumps({
30+
"function": "combine",
31+
"mean_ms": total / ITERATIONS,
32+
"iterations": ITERATIONS,
33+
"total_ms": total,
34+
}))
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Benchmark: pd.timedelta_range — evenly-spaced TimedeltaIndex factory."""
2+
import json
3+
import time
4+
import pandas as pd
5+
6+
SIZE = 1_000
7+
WARMUP = 5
8+
ITERATIONS = 200
9+
10+
# Warm-up: three usage patterns
11+
for _ in range(WARMUP):
12+
pd.timedelta_range(start="0 days", periods=SIZE, freq="h")
13+
pd.timedelta_range(start="0 days", end=f"{SIZE} days", freq="D")
14+
pd.timedelta_range(start="0 days", end="10 days", periods=SIZE)
15+
16+
start = time.perf_counter()
17+
for _ in range(ITERATIONS):
18+
pd.timedelta_range(start="0 days", periods=SIZE, freq="h")
19+
pd.timedelta_range(start="0 days", end=f"{SIZE} days", freq="D")
20+
pd.timedelta_range(start="0 days", end="10 days", periods=SIZE)
21+
total = (time.perf_counter() - start) * 1000
22+
23+
print(json.dumps({
24+
"function": "timedelta_range",
25+
"mean_ms": total / ITERATIONS,
26+
"iterations": ITERATIONS,
27+
"total_ms": total,
28+
}))

benchmarks/tsb/bench_combine.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Benchmark: combineSeries / combineDataFrame — element-wise binary combine.
3+
* Outputs JSON: {"function": "combine", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { Series, DataFrame, combineSeries, combineDataFrame } from "../../src/index.js";
6+
7+
const SIZE = 10_000;
8+
const WARMUP = 5;
9+
const ITERATIONS = 100;
10+
11+
const a = new Series({ data: Array.from({ length: SIZE }, (_, i) => i), index: Array.from({ length: SIZE }, (_, i) => i) });
12+
const b = new Series({ data: Array.from({ length: SIZE }, (_, i) => SIZE - i), index: Array.from({ length: SIZE }, (_, i) => i) });
13+
14+
const dfA = DataFrame.fromColumns({
15+
x: Array.from({ length: SIZE }, (_, i) => i),
16+
y: Array.from({ length: SIZE }, (_, i) => i * 2),
17+
});
18+
const dfB = DataFrame.fromColumns({
19+
x: Array.from({ length: SIZE }, (_, i) => SIZE - i),
20+
z: Array.from({ length: SIZE }, (_, i) => i * 3),
21+
});
22+
23+
const addFn = (p: unknown, q: unknown) => (p as number) + (q as number);
24+
25+
for (let i = 0; i < WARMUP; i++) {
26+
combineSeries(a, b, addFn, 0);
27+
combineDataFrame(dfA, dfB, addFn, { fillValue: 0 });
28+
}
29+
30+
const start = performance.now();
31+
for (let i = 0; i < ITERATIONS; i++) {
32+
combineSeries(a, b, addFn, 0);
33+
combineDataFrame(dfA, dfB, addFn, { fillValue: 0 });
34+
}
35+
const total = performance.now() - start;
36+
37+
console.log(
38+
JSON.stringify({
39+
function: "combine",
40+
mean_ms: total / ITERATIONS,
41+
iterations: ITERATIONS,
42+
total_ms: total,
43+
}),
44+
);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Benchmark: timedelta_range — evenly-spaced TimedeltaIndex factory.
3+
* Outputs JSON: {"function": "timedelta_range", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { timedelta_range } from "../../src/index.js";
6+
7+
const SIZE = 1_000;
8+
const WARMUP = 5;
9+
const ITERATIONS = 200;
10+
11+
// Warm-up: three usage patterns
12+
for (let i = 0; i < WARMUP; i++) {
13+
// start + periods + freq
14+
timedelta_range({ start: "0 days", periods: SIZE, freq: "H" });
15+
// start + end + freq
16+
timedelta_range({ start: "0 days", end: `${SIZE} days`, freq: "D" });
17+
// start + end + periods (linspace)
18+
timedelta_range({ start: "0 days", end: "10 days", periods: SIZE });
19+
}
20+
21+
const start = performance.now();
22+
for (let i = 0; i < ITERATIONS; i++) {
23+
timedelta_range({ start: "0 days", periods: SIZE, freq: "H" });
24+
timedelta_range({ start: "0 days", end: `${SIZE} days`, freq: "D" });
25+
timedelta_range({ start: "0 days", end: "10 days", periods: SIZE });
26+
}
27+
const total = performance.now() - start;
28+
29+
console.log(
30+
JSON.stringify({
31+
function: "timedelta_range",
32+
mean_ms: total / ITERATIONS,
33+
iterations: ITERATIONS,
34+
total_ms: total,
35+
}),
36+
);

0 commit comments

Comments
 (0)