Skip to content

Commit 9191c69

Browse files
Iteration 136: Add 8 benchmark pairs (396 total, +8 vs 388)
- bench_series_any_all: anySeries / allSeries boolean reductions - bench_dataframe_any_all: anyDataFrame / allDataFrame boolean reductions - bench_dataframe_nunique: nuniqueDataFrame per-column unique counts - bench_series_crosstab: seriesCrosstab two-series cross-tabulation - bench_bdate_range: bdate_range business-day DatetimeIndex generation - bench_series_radd_rsub: seriesRadd / seriesRsub / seriesRmul / seriesRdiv reverse arithmetic - bench_dataframe_radd_rsub: dataFrameRadd / dataFrameRsub / dataFrameRmul / dataFrameRdiv reverse arithmetic - bench_series_exp_log: seriesExp / seriesLog2 / seriesLog10 / seriesSign extended math Run: https://github.com/githubnext/tsessebe/actions/runs/24536797293 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 46f4b4c commit 9191c69

16 files changed

Lines changed: 559 additions & 0 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Benchmark: pd.bdate_range — generate business-day DatetimeIndex with 1000 periods.
3+
Outputs JSON: {"function": "bdate_range", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
"""
5+
import json
6+
import time
7+
import pandas as pd
8+
9+
WARMUP = 5
10+
ITERATIONS = 100
11+
12+
for _ in range(WARMUP):
13+
pd.bdate_range(start="2020-01-01", periods=1000)
14+
15+
start = time.perf_counter()
16+
for _ in range(ITERATIONS):
17+
pd.bdate_range(start="2020-01-01", periods=1000)
18+
total = (time.perf_counter() - start) * 1000
19+
20+
print(json.dumps({
21+
"function": "bdate_range",
22+
"mean_ms": total / ITERATIONS,
23+
"iterations": ITERATIONS,
24+
"total_ms": total,
25+
}))
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Benchmark: DataFrame.any() / all() — boolean reductions on 100k-row DataFrame.
3+
Outputs JSON: {"function": "dataframe_any_all", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
"""
5+
import json
6+
import time
7+
import numpy as np
8+
import pandas as pd
9+
10+
SIZE = 100_000
11+
WARMUP = 5
12+
ITERATIONS = 50
13+
14+
df = pd.DataFrame({
15+
"a": np.arange(SIZE) % 2 == 0,
16+
"b": np.arange(SIZE) % 3 != 0,
17+
"c": np.arange(SIZE) > 0,
18+
})
19+
20+
for _ in range(WARMUP):
21+
df.any()
22+
df.all()
23+
24+
start = time.perf_counter()
25+
for _ in range(ITERATIONS):
26+
df.any()
27+
df.all()
28+
total = (time.perf_counter() - start) * 1000
29+
30+
print(json.dumps({
31+
"function": "dataframe_any_all",
32+
"mean_ms": total / ITERATIONS,
33+
"iterations": ITERATIONS,
34+
"total_ms": total,
35+
}))
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Benchmark: DataFrame.nunique() — count unique values per column on 100k-row DataFrame.
3+
Outputs JSON: {"function": "dataframe_nunique", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
"""
5+
import json
6+
import time
7+
import numpy as np
8+
import pandas as pd
9+
10+
SIZE = 100_000
11+
WARMUP = 5
12+
ITERATIONS = 20
13+
14+
df = pd.DataFrame({
15+
"cat": np.arange(SIZE) % 100,
16+
"val": np.arange(SIZE) % 500,
17+
"grp": np.arange(SIZE) % 10,
18+
})
19+
20+
for _ in range(WARMUP):
21+
df.nunique()
22+
23+
start = time.perf_counter()
24+
for _ in range(ITERATIONS):
25+
df.nunique()
26+
total = (time.perf_counter() - start) * 1000
27+
28+
print(json.dumps({
29+
"function": "dataframe_nunique",
30+
"mean_ms": total / ITERATIONS,
31+
"iterations": ITERATIONS,
32+
"total_ms": total,
33+
}))
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""
2+
Benchmark: DataFrame.radd / rsub / rmul / rdiv — reverse arithmetic on 100k-row DataFrame.
3+
Outputs JSON: {"function": "dataframe_radd_rsub", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
"""
5+
import json
6+
import time
7+
import numpy as np
8+
import pandas as pd
9+
10+
SIZE = 100_000
11+
WARMUP = 5
12+
ITERATIONS = 50
13+
14+
df = pd.DataFrame({
15+
"x": (np.arange(SIZE) % 1000 + 1).astype(float),
16+
"y": (np.arange(SIZE) % 500 + 0.5),
17+
})
18+
19+
for _ in range(WARMUP):
20+
df.radd(100)
21+
df.rsub(100)
22+
df.rmul(2)
23+
df.rdiv(1000)
24+
25+
start = time.perf_counter()
26+
for _ in range(ITERATIONS):
27+
df.radd(100)
28+
df.rsub(100)
29+
df.rmul(2)
30+
df.rdiv(1000)
31+
total = (time.perf_counter() - start) * 1000
32+
33+
print(json.dumps({
34+
"function": "dataframe_radd_rsub",
35+
"mean_ms": total / ITERATIONS,
36+
"iterations": ITERATIONS,
37+
"total_ms": total,
38+
}))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""
2+
Benchmark: Series.any() / all() — boolean reductions on 100k-element Series.
3+
Outputs JSON: {"function": "series_any_all", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
"""
5+
import json
6+
import time
7+
import numpy as np
8+
import pandas as pd
9+
10+
SIZE = 100_000
11+
WARMUP = 5
12+
ITERATIONS = 50
13+
14+
s = pd.Series(np.arange(SIZE) % 2 == 0)
15+
16+
for _ in range(WARMUP):
17+
s.any()
18+
s.all()
19+
20+
start = time.perf_counter()
21+
for _ in range(ITERATIONS):
22+
s.any()
23+
s.all()
24+
total = (time.perf_counter() - start) * 1000
25+
26+
print(json.dumps({
27+
"function": "series_any_all",
28+
"mean_ms": total / ITERATIONS,
29+
"iterations": ITERATIONS,
30+
"total_ms": total,
31+
}))
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Benchmark: pd.crosstab — cross-tabulation of two categorical Series.
3+
Outputs JSON: {"function": "series_crosstab", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
"""
5+
import json
6+
import time
7+
import numpy as np
8+
import pandas as pd
9+
10+
SIZE = 10_000
11+
WARMUP = 5
12+
ITERATIONS = 20
13+
14+
categories_a = ["apple", "banana", "cherry", "date", "elderberry"]
15+
categories_b = ["north", "south", "east", "west"]
16+
17+
a = pd.Series([categories_a[i % len(categories_a)] for i in range(SIZE)], name="product")
18+
b = pd.Series([categories_b[i % len(categories_b)] for i in range(SIZE)], name="region")
19+
20+
for _ in range(WARMUP):
21+
pd.crosstab(a, b)
22+
23+
start = time.perf_counter()
24+
for _ in range(ITERATIONS):
25+
pd.crosstab(a, b)
26+
total = (time.perf_counter() - start) * 1000
27+
28+
print(json.dumps({
29+
"function": "series_crosstab",
30+
"mean_ms": total / ITERATIONS,
31+
"iterations": ITERATIONS,
32+
"total_ms": total,
33+
}))
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Benchmark: Series.map(np.exp) / log2 / log10 / sign — extended math on 100k-element Series.
3+
Outputs JSON: {"function": "series_exp_log", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
"""
5+
import json
6+
import time
7+
import numpy as np
8+
import pandas as pd
9+
10+
SIZE = 100_000
11+
WARMUP = 5
12+
ITERATIONS = 50
13+
14+
s = pd.Series((np.arange(SIZE) % 1000 + 1).astype(float))
15+
16+
for _ in range(WARMUP):
17+
np.exp(s)
18+
np.log2(s)
19+
np.log10(s)
20+
np.sign(s)
21+
22+
start = time.perf_counter()
23+
for _ in range(ITERATIONS):
24+
np.exp(s)
25+
np.log2(s)
26+
np.log10(s)
27+
np.sign(s)
28+
total = (time.perf_counter() - start) * 1000
29+
30+
print(json.dumps({
31+
"function": "series_exp_log",
32+
"mean_ms": total / ITERATIONS,
33+
"iterations": ITERATIONS,
34+
"total_ms": total,
35+
}))
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Benchmark: Series.radd / rsub / rmul / rdiv — reverse arithmetic on 100k-element Series.
3+
Outputs JSON: {"function": "series_radd_rsub", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
"""
5+
import json
6+
import time
7+
import numpy as np
8+
import pandas as pd
9+
10+
SIZE = 100_000
11+
WARMUP = 5
12+
ITERATIONS = 50
13+
14+
s = pd.Series((np.arange(SIZE) % 1000) + 1, dtype=float)
15+
16+
for _ in range(WARMUP):
17+
s.radd(100)
18+
s.rsub(100)
19+
s.rmul(2)
20+
s.rdiv(1000)
21+
22+
start = time.perf_counter()
23+
for _ in range(ITERATIONS):
24+
s.radd(100)
25+
s.rsub(100)
26+
s.rmul(2)
27+
s.rdiv(1000)
28+
total = (time.perf_counter() - start) * 1000
29+
30+
print(json.dumps({
31+
"function": "series_radd_rsub",
32+
"mean_ms": total / ITERATIONS,
33+
"iterations": ITERATIONS,
34+
"total_ms": total,
35+
}))
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Benchmark: bdate_range — generate business-day DatetimeIndex with 1000 periods.
3+
* Outputs JSON: {"function": "bdate_range", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { bdate_range } from "../../src/index.ts";
6+
7+
const WARMUP = 5;
8+
const ITERATIONS = 100;
9+
10+
for (let i = 0; i < WARMUP; i++) {
11+
bdate_range({ start: "2020-01-01", periods: 1000 });
12+
}
13+
14+
const start = performance.now();
15+
for (let i = 0; i < ITERATIONS; i++) {
16+
bdate_range({ start: "2020-01-01", periods: 1000 });
17+
}
18+
const total = performance.now() - start;
19+
20+
console.log(
21+
JSON.stringify({
22+
function: "bdate_range",
23+
mean_ms: total / ITERATIONS,
24+
iterations: ITERATIONS,
25+
total_ms: total,
26+
}),
27+
);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Benchmark: anyDataFrame / allDataFrame — boolean reductions on 100k-row DataFrame.
3+
* Outputs JSON: {"function": "dataframe_any_all", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { DataFrame, Series, anyDataFrame, allDataFrame } from "../../src/index.ts";
6+
7+
const SIZE = 100_000;
8+
const WARMUP = 5;
9+
const ITERATIONS = 50;
10+
11+
const df = new DataFrame({
12+
columns: new Map([
13+
["a", new Series({ data: Array.from({ length: SIZE }, (_, i) => i % 2 === 0) })],
14+
["b", new Series({ data: Array.from({ length: SIZE }, (_, i) => i % 3 !== 0) })],
15+
["c", new Series({ data: Array.from({ length: SIZE }, (_, i) => i > 0) })],
16+
]),
17+
});
18+
19+
for (let i = 0; i < WARMUP; i++) {
20+
anyDataFrame(df);
21+
allDataFrame(df);
22+
}
23+
24+
const start = performance.now();
25+
for (let i = 0; i < ITERATIONS; i++) {
26+
anyDataFrame(df);
27+
allDataFrame(df);
28+
}
29+
const total = performance.now() - start;
30+
31+
console.log(
32+
JSON.stringify({
33+
function: "dataframe_any_all",
34+
mean_ms: total / ITERATIONS,
35+
iterations: ITERATIONS,
36+
total_ms: total,
37+
}),
38+
);

0 commit comments

Comments
 (0)