Skip to content

Commit a5e0b23

Browse files
authored
Merge pull request #141 from githubnext/autoloop/perf-comparison-3c596789b15fd053
[Autoloop] [Autoloop: perf-comparison]
2 parents c99c155 + a06fe02 commit a5e0b23

658 files changed

Lines changed: 16731 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Benchmark: DataFrame.map formatter on 10k-row DataFrame"""
2+
import json, time
3+
import pandas as pd
4+
5+
ROWS = 10_000
6+
WARMUP = 3
7+
ITERATIONS = 10
8+
df = pd.DataFrame({"a": [i * 1.234 for i in range(ROWS)], "b": [i * 5.678 for i in range(ROWS)]})
9+
10+
for _ in range(WARMUP):
11+
df.map(lambda v: f"{v:.2f}")
12+
13+
start = time.perf_counter()
14+
for _ in range(ITERATIONS):
15+
df.map(lambda v: f"{v:.2f}")
16+
total = (time.perf_counter() - start) * 1000
17+
print(json.dumps({"function": "apply_dataframe_formatter", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total}))
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""Benchmark: apply formatter to 100k-element pandas Series"""
2+
import json, time
3+
import pandas as pd
4+
5+
ROWS = 100_000
6+
WARMUP = 3
7+
ITERATIONS = 10
8+
s = pd.Series([i * 1.234 for i in range(ROWS)])
9+
10+
for _ in range(WARMUP):
11+
s.map(lambda v: f"{v:.2f}")
12+
13+
start = time.perf_counter()
14+
for _ in range(ITERATIONS):
15+
s.map(lambda v: f"{v:.2f}")
16+
total = (time.perf_counter() - start) * 1000
17+
print(json.dumps({"function": "apply_series_formatter", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total}))
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"""Benchmark: np.arange and np.linspace generating 100k-element arrays"""
2+
import json, time
3+
import numpy as np
4+
5+
N = 100_000
6+
WARMUP = 3
7+
ITERATIONS = 10
8+
9+
for _ in range(WARMUP):
10+
np.arange(0, N, 1)
11+
np.linspace(0, 1, N)
12+
13+
start = time.perf_counter()
14+
for _ in range(ITERATIONS):
15+
np.arange(0, N, 1)
16+
np.linspace(0, 1, N)
17+
total = (time.perf_counter() - start) * 1000
18+
print(json.dumps({"function": "arange_linspace", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total}))
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Benchmark: Series.astype() — cast Series dtype."""
2+
import json, time
3+
import pandas as pd
4+
5+
SIZE = 100_000
6+
WARMUP = 5
7+
ITERATIONS = 50
8+
9+
float_series = pd.Series([i * 1.5 for i in range(SIZE)])
10+
int_series = pd.Series([i for i in range(SIZE)])
11+
12+
for _ in range(WARMUP):
13+
float_series.astype("int32")
14+
int_series.astype("float64")
15+
int_series.astype("str")
16+
17+
times = []
18+
for _ in range(ITERATIONS):
19+
t0 = time.perf_counter()
20+
float_series.astype("int32")
21+
int_series.astype("float64")
22+
int_series.astype("str")
23+
times.append((time.perf_counter() - t0) * 1000)
24+
25+
total_ms = sum(times)
26+
print(json.dumps({"function":"astype_series","mean_ms":round(total_ms/ITERATIONS,3),"iterations":ITERATIONS,"total_ms":round(total_ms,3)}))
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Benchmark: pandas Series attrs advanced — individual attr get/set/delete/copy/merge"""
2+
import json, time
3+
import pandas as pd
4+
5+
WARMUP = 3
6+
ITERATIONS = 1_000
7+
8+
s = pd.Series(range(1_000))
9+
s2 = pd.Series(range(1_000))
10+
11+
for _ in range(WARMUP):
12+
s.attrs["unit"] = "meters"
13+
_ = s.attrs.get("unit")
14+
_ = bool(s.attrs)
15+
s2.attrs.update(dict(s.attrs))
16+
s.attrs.update({"version": 1})
17+
s.attrs.pop("unit", None)
18+
s.attrs.clear()
19+
20+
start = time.perf_counter()
21+
for i in range(ITERATIONS):
22+
s.attrs["unit"] = "meters"
23+
_ = s.attrs.get("unit")
24+
_ = bool(s.attrs)
25+
s2.attrs.update(dict(s.attrs))
26+
s.attrs.update({"version": i})
27+
s.attrs.pop("unit", None)
28+
s.attrs.clear()
29+
total = (time.perf_counter() - start) * 1000
30+
print(json.dumps({"function": "attrs_advanced", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total}))
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import pandas as pd, time, json
2+
N = 100_000
3+
s = pd.Series(range(N))
4+
s.attrs = {"a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8}
5+
WARMUP = 3
6+
ITERS = 10_000
7+
for _ in range(WARMUP):
8+
_ = len(s.attrs)
9+
_ = list(s.attrs.keys())
10+
t0 = time.perf_counter()
11+
for _ in range(ITERS):
12+
_ = len(s.attrs)
13+
_ = list(s.attrs.keys())
14+
total = (time.perf_counter() - t0) * 1000
15+
print(json.dumps({"function": "attrs_count_keys", "mean_ms": total / ITERS, "iterations": ITERS, "total_ms": total}))
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import pandas as pd, time, json
2+
N = 10_000
3+
s = pd.Series(range(N))
4+
attrs_data = {"unit": "meters", "created": "2024-01-01", "source": "sensor-1", "version": 2}
5+
WARMUP = 3
6+
ITERS = 100
7+
for _ in range(WARMUP):
8+
s.attrs.update(attrs_data)
9+
_ = dict(s.attrs)
10+
s.attrs["version"] = 99
11+
s2 = s.copy()
12+
s2.attrs.update({"extra": "x"})
13+
t0 = time.perf_counter()
14+
for i in range(ITERS):
15+
s.attrs.update(attrs_data)
16+
_ = dict(s.attrs)
17+
s.attrs["version"] = i
18+
s2 = s.copy()
19+
s2.attrs.update({"extra": "x"})
20+
total = (time.perf_counter() - t0) * 1000
21+
print(json.dumps({"function": "attrs_ops", "mean_ms": total / ITERS, "iterations": ITERS, "total_ms": total}))

benchmarks/pandas/bench_between.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Benchmark: Series.between() — element-wise range check."""
2+
import json, time
3+
import pandas as pd
4+
5+
SIZE = 100_000
6+
WARMUP = 5
7+
ITERATIONS = 50
8+
9+
s = pd.Series([float(i) for i in range(SIZE)])
10+
11+
for _ in range(WARMUP):
12+
s.between(25000.0, 75000.0)
13+
14+
times = []
15+
for _ in range(ITERATIONS):
16+
t0 = time.perf_counter()
17+
s.between(25000.0, 75000.0)
18+
times.append((time.perf_counter() - t0) * 1000)
19+
20+
total_ms = sum(times)
21+
print(json.dumps({"function":"between","mean_ms":round(total_ms/ITERATIONS,3),"iterations":ITERATIONS,"total_ms":round(total_ms,3)}))
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""Benchmark: cat_add_remove_categories — pandas CategoricalIndex add_categories/remove_categories on 100k-element Series"""
2+
import json
3+
import time
4+
import pandas as pd
5+
6+
ROWS = 100_000
7+
WARMUP = 3
8+
ITERATIONS = 10
9+
10+
cats = ["a", "b", "c", "d"]
11+
s = pd.Categorical([cats[i % len(cats)] for i in range(ROWS)], categories=cats)
12+
13+
for _ in range(WARMUP):
14+
_ = s.add_categories(["e", "f"])
15+
_ = s.remove_categories(["d"])
16+
17+
start = time.perf_counter()
18+
for _ in range(ITERATIONS):
19+
_ = s.add_categories(["e", "f"])
20+
_ = s.remove_categories(["d"])
21+
total = (time.perf_counter() - start) * 1000
22+
23+
print(json.dumps({"function": "cat_add_remove_categories", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total}))
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""Benchmark: pd.crosstab on two 100k-element categorical Series"""
2+
import json, time
3+
import pandas as pd
4+
5+
ROWS = 100_000
6+
WARMUP = 3
7+
ITERATIONS = 10
8+
cats1 = ["a", "b", "c", "d"]
9+
cats2 = ["x", "y", "z"]
10+
s1 = pd.Series([cats1[i % 4] for i in range(ROWS)])
11+
s2 = pd.Series([cats2[i % 3] for i in range(ROWS)])
12+
13+
for _ in range(WARMUP):
14+
pd.crosstab(s1, s2)
15+
16+
start = time.perf_counter()
17+
for _ in range(ITERATIONS):
18+
pd.crosstab(s1, s2)
19+
total = (time.perf_counter() - start) * 1000
20+
print(json.dumps({"function": "cat_cross_tab", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total}))

0 commit comments

Comments
 (0)