Skip to content

Commit 5291ffd

Browse files
Iteration 244: 5 new benchmark pairs (539 total, +5 vs best 534)
Add benchmark pairs: str_swapcase_capitalize, dt_strftime, series_reflected_arith, dataframe_reflected_arith, any_all. Run: https://github.com/githubnext/tsessebe/actions/runs/24644387987 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 634e5bf commit 5291ffd

10 files changed

Lines changed: 342 additions & 0 deletions

benchmarks/pandas/bench_any_all.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
"""Benchmark: any_all — Series.any / all and DataFrame.any / all on 100k rows."""
2+
import json, time
3+
import numpy as np
4+
import pandas as pd
5+
6+
SIZE = 100_000
7+
WARMUP = 5
8+
ITERATIONS = 50
9+
10+
s = pd.Series(np.arange(SIZE) % 2 == 0)
11+
df = pd.DataFrame({
12+
"a": np.arange(SIZE) % 3 != 0,
13+
"b": np.arange(SIZE) > 0,
14+
"c": np.ones(SIZE, dtype=bool),
15+
})
16+
17+
for _ in range(WARMUP):
18+
s.any()
19+
s.all()
20+
df.any()
21+
df.all()
22+
23+
start = time.perf_counter()
24+
for _ in range(ITERATIONS):
25+
s.any()
26+
s.all()
27+
df.any()
28+
df.all()
29+
total = (time.perf_counter() - start) * 1000
30+
31+
print(json.dumps({
32+
"function": "any_all",
33+
"mean_ms": total / ITERATIONS,
34+
"iterations": ITERATIONS,
35+
"total_ms": total,
36+
}))
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Benchmark: dataframe_reflected_arith — DataFrame.radd / rsub / rmul / rdiv."""
2+
import json, time
3+
import numpy as np
4+
import pandas as pd
5+
6+
ROWS = 10_000
7+
WARMUP = 5
8+
ITERATIONS = 30
9+
10+
df = pd.DataFrame({
11+
"a": np.arange(ROWS) * 1.5,
12+
"b": (np.arange(ROWS) % 100) + 1.0,
13+
"c": np.arange(ROWS) * 0.25,
14+
})
15+
16+
for _ in range(WARMUP):
17+
df.radd(10)
18+
df.rsub(1000)
19+
df.rmul(3)
20+
df.rdiv(100)
21+
22+
start = time.perf_counter()
23+
for _ in range(ITERATIONS):
24+
df.radd(10)
25+
df.rsub(1000)
26+
df.rmul(3)
27+
df.rdiv(100)
28+
total = (time.perf_counter() - start) * 1000
29+
30+
print(json.dumps({
31+
"function": "dataframe_reflected_arith",
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+
"""Benchmark: dt_strftime — dt.strftime formatting on 100k datetime values."""
2+
import json, time
3+
import pandas as pd
4+
5+
ROWS = 100_000
6+
WARMUP = 3
7+
ITERATIONS = 10
8+
9+
dates = pd.date_range("2024-01-01", periods=ROWS, freq="1min")
10+
s = pd.Series(dates)
11+
12+
for _ in range(WARMUP):
13+
s.dt.strftime("%Y-%m-%d")
14+
s.dt.strftime("%H:%M:%S")
15+
16+
start = time.perf_counter()
17+
for _ in range(ITERATIONS):
18+
s.dt.strftime("%Y-%m-%d")
19+
s.dt.strftime("%H:%M:%S")
20+
total = (time.perf_counter() - start) * 1000
21+
22+
print(json.dumps({
23+
"function": "dt_strftime",
24+
"mean_ms": total / ITERATIONS,
25+
"iterations": ITERATIONS,
26+
"total_ms": total,
27+
}))
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Benchmark: series_reflected_arith — Series.radd / rsub / rmul / rdiv."""
2+
import json, time
3+
import numpy as np
4+
import pandas as pd
5+
6+
SIZE = 100_000
7+
WARMUP = 5
8+
ITERATIONS = 50
9+
10+
a = pd.Series(np.arange(SIZE) * 1.5)
11+
b = pd.Series((np.arange(SIZE) % 1000) + 1.0)
12+
13+
for _ in range(WARMUP):
14+
a.radd(10)
15+
a.rsub(1000)
16+
a.rmul(3)
17+
b.rdiv(100)
18+
19+
start = time.perf_counter()
20+
for _ in range(ITERATIONS):
21+
a.radd(10)
22+
a.rsub(1000)
23+
a.rmul(3)
24+
b.rdiv(100)
25+
total = (time.perf_counter() - start) * 1000
26+
27+
print(json.dumps({
28+
"function": "series_reflected_arith",
29+
"mean_ms": total / ITERATIONS,
30+
"iterations": ITERATIONS,
31+
"total_ms": total,
32+
}))
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Benchmark: str_swapcase_capitalize — str.swapcase and str.capitalize on 100k strings."""
2+
import json, time
3+
import pandas as pd
4+
5+
ROWS = 100_000
6+
WARMUP = 3
7+
ITERATIONS = 10
8+
9+
data = [f"Hello World {i % 500} EXAMPLE" for i in range(ROWS)]
10+
s = pd.Series(data)
11+
12+
for _ in range(WARMUP):
13+
s.str.swapcase()
14+
s.str.capitalize()
15+
16+
start = time.perf_counter()
17+
for _ in range(ITERATIONS):
18+
s.str.swapcase()
19+
s.str.capitalize()
20+
total = (time.perf_counter() - start) * 1000
21+
22+
print(json.dumps({
23+
"function": "str_swapcase_capitalize",
24+
"mean_ms": total / ITERATIONS,
25+
"iterations": ITERATIONS,
26+
"total_ms": total,
27+
}))

benchmarks/tsb/bench_any_all.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Benchmark: any_all — anySeries / allSeries / anyDataFrame / allDataFrame on 100k rows.
3+
* Outputs JSON: {"function": "any_all", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { Series, DataFrame, anySeries, allSeries, anyDataFrame, allDataFrame } from "../../src/index.ts";
6+
7+
const SIZE = 100_000;
8+
const WARMUP = 5;
9+
const ITERATIONS = 50;
10+
11+
const s = new Series({ data: Array.from({ length: SIZE }, (_, i) => i % 2 === 0) });
12+
const df = DataFrame.fromColumns({
13+
a: Array.from({ length: SIZE }, (_, i) => i % 3 !== 0),
14+
b: Array.from({ length: SIZE }, (_, i) => i > 0),
15+
c: Array.from({ length: SIZE }, () => true),
16+
});
17+
18+
for (let i = 0; i < WARMUP; i++) {
19+
anySeries(s);
20+
allSeries(s);
21+
anyDataFrame(df);
22+
allDataFrame(df);
23+
}
24+
25+
const start = performance.now();
26+
for (let i = 0; i < ITERATIONS; i++) {
27+
anySeries(s);
28+
allSeries(s);
29+
anyDataFrame(df);
30+
allDataFrame(df);
31+
}
32+
const total = performance.now() - start;
33+
34+
console.log(
35+
JSON.stringify({
36+
function: "any_all",
37+
mean_ms: total / ITERATIONS,
38+
iterations: ITERATIONS,
39+
total_ms: total,
40+
}),
41+
);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Benchmark: dataframe_reflected_arith — dataFrameRadd / dataFrameRsub / dataFrameRmul / dataFrameRdiv.
3+
* Outputs JSON: {"function": "dataframe_reflected_arith", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { DataFrame, dataFrameRadd, dataFrameRsub, dataFrameRmul, dataFrameRdiv } from "../../src/index.ts";
6+
7+
const SIZE = 50_000;
8+
const WARMUP = 5;
9+
const ITERATIONS = 30;
10+
11+
const df = DataFrame.fromColumns({
12+
a: Array.from({ length: SIZE }, (_, i) => i * 1.5),
13+
b: Array.from({ length: SIZE }, (_, i) => (i % 100) + 1),
14+
c: Array.from({ length: SIZE }, (_, i) => i * 0.25),
15+
});
16+
17+
for (let i = 0; i < WARMUP; i++) {
18+
dataFrameRadd(df, 10);
19+
dataFrameRsub(df, 1000);
20+
dataFrameRmul(df, 3);
21+
dataFrameRdiv(df, 100);
22+
}
23+
24+
const start = performance.now();
25+
for (let i = 0; i < ITERATIONS; i++) {
26+
dataFrameRadd(df, 10);
27+
dataFrameRsub(df, 1000);
28+
dataFrameRmul(df, 3);
29+
dataFrameRdiv(df, 100);
30+
}
31+
const total = performance.now() - start;
32+
33+
console.log(
34+
JSON.stringify({
35+
function: "dataframe_reflected_arith",
36+
mean_ms: total / ITERATIONS,
37+
iterations: ITERATIONS,
38+
total_ms: total,
39+
}),
40+
);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Benchmark: dt_strftime — dt.strftime formatting on 100k datetime values.
3+
* Outputs JSON: {"function": "dt_strftime", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { Series } from "../../src/index.ts";
6+
7+
const ROWS = 100_000;
8+
const WARMUP = 3;
9+
const ITERATIONS = 10;
10+
11+
const now = Date.now();
12+
const data = Array.from({ length: ROWS }, (_, i) => new Date(now + i * 60_000));
13+
const s = new Series({ data });
14+
15+
for (let i = 0; i < WARMUP; i++) {
16+
s.dt.strftime("%Y-%m-%d");
17+
s.dt.strftime("%H:%M:%S");
18+
}
19+
20+
const start = performance.now();
21+
for (let i = 0; i < ITERATIONS; i++) {
22+
s.dt.strftime("%Y-%m-%d");
23+
s.dt.strftime("%H:%M:%S");
24+
}
25+
const total = performance.now() - start;
26+
27+
console.log(
28+
JSON.stringify({
29+
function: "dt_strftime",
30+
mean_ms: total / ITERATIONS,
31+
iterations: ITERATIONS,
32+
total_ms: total,
33+
}),
34+
);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Benchmark: series_reflected_arith — seriesRadd / seriesRsub / seriesRmul / seriesRdiv.
3+
* Outputs JSON: {"function": "series_reflected_arith", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { Series, seriesRadd, seriesRsub, seriesRmul, seriesRdiv } from "../../src/index.ts";
6+
7+
const SIZE = 100_000;
8+
const WARMUP = 5;
9+
const ITERATIONS = 50;
10+
11+
const a = new Series({ data: Array.from({ length: SIZE }, (_, i) => i * 1.5) });
12+
const b = new Series({ data: Array.from({ length: SIZE }, (_, i) => (i % 1000) + 1) });
13+
14+
for (let i = 0; i < WARMUP; i++) {
15+
seriesRadd(a, 10);
16+
seriesRsub(a, 1000);
17+
seriesRmul(a, 3);
18+
seriesRdiv(b, 100);
19+
}
20+
21+
const start = performance.now();
22+
for (let i = 0; i < ITERATIONS; i++) {
23+
seriesRadd(a, 10);
24+
seriesRsub(a, 1000);
25+
seriesRmul(a, 3);
26+
seriesRdiv(b, 100);
27+
}
28+
const total = performance.now() - start;
29+
30+
console.log(
31+
JSON.stringify({
32+
function: "series_reflected_arith",
33+
mean_ms: total / ITERATIONS,
34+
iterations: ITERATIONS,
35+
total_ms: total,
36+
}),
37+
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Benchmark: str_swapcase_capitalize — str.swapcase and str.capitalize on 100k strings.
3+
* Outputs JSON: {"function": "str_swapcase_capitalize", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { Series } from "../../src/index.ts";
6+
7+
const ROWS = 100_000;
8+
const WARMUP = 3;
9+
const ITERATIONS = 10;
10+
11+
const data = Array.from({ length: ROWS }, (_, i) => `Hello World ${i % 500} EXAMPLE`);
12+
const s = new Series({ data });
13+
14+
for (let i = 0; i < WARMUP; i++) {
15+
s.str.swapcase();
16+
s.str.capitalize();
17+
}
18+
19+
const start = performance.now();
20+
for (let i = 0; i < ITERATIONS; i++) {
21+
s.str.swapcase();
22+
s.str.capitalize();
23+
}
24+
const total = performance.now() - start;
25+
26+
console.log(
27+
JSON.stringify({
28+
function: "str_swapcase_capitalize",
29+
mean_ms: total / ITERATIONS,
30+
iterations: ITERATIONS,
31+
total_ms: total,
32+
}),
33+
);

0 commit comments

Comments
 (0)