Skip to content

Commit faf3c84

Browse files
Iteration 48: Add 29 new benchmark pairs (rolling variants, expanding, ewm, series ops, categorical, DataFrame ops)
Run: https://github.com/githubnext/tsessebe/actions/runs/24368561859 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 840a02e commit faf3c84

58 files changed

Lines changed: 1332 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Benchmark: Categorical from codes on 100k-element array"""
2+
import json, time
3+
import numpy as np
4+
import pandas as pd
5+
6+
ROWS = 100_000
7+
WARMUP = 3
8+
ITERATIONS = 10
9+
10+
categories = ["apple", "banana", "cherry", "date", "elderberry"]
11+
codes = np.arange(ROWS) % len(categories)
12+
13+
for _ in range(WARMUP):
14+
pd.Categorical.from_codes(codes, categories=categories)
15+
16+
start = time.perf_counter()
17+
for _ in range(ITERATIONS):
18+
pd.Categorical.from_codes(codes, categories=categories)
19+
total = (time.perf_counter() - start) * 1000
20+
21+
print(json.dumps({ "function": "cat_from_codes", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total }))

benchmarks/pandas/bench_cut.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Benchmark: cut (bin into 10 bins) on 100k-element Series"""
2+
import json, time
3+
import numpy as np
4+
import pandas as pd
5+
6+
ROWS = 100_000
7+
WARMUP = 3
8+
ITERATIONS = 10
9+
10+
data = (np.arange(ROWS) % 10000) * 0.01
11+
s = pd.Series(data)
12+
13+
for _ in range(WARMUP):
14+
pd.cut(s, 10)
15+
16+
start = time.perf_counter()
17+
for _ in range(ITERATIONS):
18+
pd.cut(s, 10)
19+
total = (time.perf_counter() - start) * 1000
20+
21+
print(json.dumps({ "function": "cut", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total }))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Benchmark: DataFrame covariance matrix on 1000x10 DataFrame"""
2+
import json, time
3+
import numpy as np
4+
import pandas as pd
5+
6+
ROWS = 1_000
7+
COLS = 10
8+
WARMUP = 3
9+
ITERATIONS = 10
10+
11+
data = {f"col{c}": np.sin(np.arange(ROWS) * 0.01 + c) for c in range(COLS)}
12+
df = pd.DataFrame(data)
13+
14+
for _ in range(WARMUP):
15+
df.cov()
16+
17+
start = time.perf_counter()
18+
for _ in range(ITERATIONS):
19+
df.cov()
20+
total = (time.perf_counter() - start) * 1000
21+
22+
print(json.dumps({ "function": "dataframe_cov", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total }))

benchmarks/pandas/bench_ewm_std.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Benchmark: ewm std (alpha=0.1) on 100k-element Series"""
2+
import json, time
3+
import numpy as np
4+
import pandas as pd
5+
6+
ROWS = 100_000
7+
WARMUP = 3
8+
ITERATIONS = 10
9+
10+
data = np.sin(np.arange(ROWS) * 0.01)
11+
s = pd.Series(data)
12+
13+
for _ in range(WARMUP):
14+
s.ewm(alpha=0.1).std()
15+
16+
start = time.perf_counter()
17+
for _ in range(ITERATIONS):
18+
s.ewm(alpha=0.1).std()
19+
total = (time.perf_counter() - start) * 1000
20+
21+
print(json.dumps({ "function": "ewm_std", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total }))

benchmarks/pandas/bench_ewm_var.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Benchmark: ewm var (alpha=0.1) on 100k-element Series"""
2+
import json, time
3+
import numpy as np
4+
import pandas as pd
5+
6+
ROWS = 100_000
7+
WARMUP = 3
8+
ITERATIONS = 10
9+
10+
data = np.sin(np.arange(ROWS) * 0.01)
11+
s = pd.Series(data)
12+
13+
for _ in range(WARMUP):
14+
s.ewm(alpha=0.1).var()
15+
16+
start = time.perf_counter()
17+
for _ in range(ITERATIONS):
18+
s.ewm(alpha=0.1).var()
19+
total = (time.perf_counter() - start) * 1000
20+
21+
print(json.dumps({ "function": "ewm_var", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total }))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Benchmark: expanding std on 100k-element Series"""
2+
import json, time
3+
import numpy as np
4+
import pandas as pd
5+
6+
ROWS = 100_000
7+
WARMUP = 3
8+
ITERATIONS = 10
9+
10+
data = np.sin(np.arange(ROWS) * 0.01)
11+
s = pd.Series(data)
12+
13+
for _ in range(WARMUP):
14+
s.expanding().std()
15+
16+
start = time.perf_counter()
17+
for _ in range(ITERATIONS):
18+
s.expanding().std()
19+
total = (time.perf_counter() - start) * 1000
20+
21+
print(json.dumps({ "function": "expanding_std", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total }))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Benchmark: expanding sum on 100k-element Series"""
2+
import json, time
3+
import numpy as np
4+
import pandas as pd
5+
6+
ROWS = 100_000
7+
WARMUP = 3
8+
ITERATIONS = 10
9+
10+
data = np.sin(np.arange(ROWS) * 0.01)
11+
s = pd.Series(data)
12+
13+
for _ in range(WARMUP):
14+
s.expanding().sum()
15+
16+
start = time.perf_counter()
17+
for _ in range(ITERATIONS):
18+
s.expanding().sum()
19+
total = (time.perf_counter() - start) * 1000
20+
21+
print(json.dumps({ "function": "expanding_sum", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total }))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Benchmark: expanding var on 100k-element Series"""
2+
import json, time
3+
import numpy as np
4+
import pandas as pd
5+
6+
ROWS = 100_000
7+
WARMUP = 3
8+
ITERATIONS = 10
9+
10+
data = np.sin(np.arange(ROWS) * 0.01)
11+
s = pd.Series(data)
12+
13+
for _ in range(WARMUP):
14+
s.expanding().var()
15+
16+
start = time.perf_counter()
17+
for _ in range(ITERATIONS):
18+
s.expanding().var()
19+
total = (time.perf_counter() - start) * 1000
20+
21+
print(json.dumps({ "function": "expanding_var", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total }))
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Benchmark: DataFrame insert column on 10000x3 DataFrame"""
2+
import json, time
3+
import numpy as np
4+
import pandas as pd
5+
6+
ROWS = 10_000
7+
WARMUP = 3
8+
ITERATIONS = 20
9+
10+
new_col = np.arange(ROWS, dtype=float) * 4
11+
12+
def make_df():
13+
return pd.DataFrame({
14+
"a": np.arange(ROWS, dtype=float),
15+
"b": np.arange(ROWS, dtype=float) * 2,
16+
"c": np.arange(ROWS, dtype=float) * 3,
17+
})
18+
19+
for _ in range(WARMUP):
20+
df = make_df()
21+
df.insert(1, "new_col", new_col)
22+
23+
start = time.perf_counter()
24+
for _ in range(ITERATIONS):
25+
df = make_df()
26+
df.insert(1, "new_col", new_col)
27+
total = (time.perf_counter() - start) * 1000
28+
29+
print(json.dumps({ "function": "insert_column", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total }))

benchmarks/pandas/bench_qcut.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Benchmark: qcut (10 quantile bins) on 100k-element Series"""
2+
import json, time
3+
import numpy as np
4+
import pandas as pd
5+
6+
ROWS = 100_000
7+
WARMUP = 3
8+
ITERATIONS = 10
9+
10+
data = (np.arange(ROWS) % 10000) * 0.01
11+
s = pd.Series(data)
12+
13+
for _ in range(WARMUP):
14+
pd.qcut(s, 10, duplicates="drop")
15+
16+
start = time.perf_counter()
17+
for _ in range(ITERATIONS):
18+
pd.qcut(s, 10, duplicates="drop")
19+
total = (time.perf_counter() - start) * 1000
20+
21+
print(json.dumps({ "function": "qcut", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total }))

0 commit comments

Comments
 (0)