Skip to content

Commit 711edfc

Browse files
authored
Merge pull request #166 from githubnext/autoloop/perf-comparison-a1c7965c
[Autoloop] [Autoloop: perf-comparison]
2 parents 8c186af + 788fabc commit 711edfc

6 files changed

Lines changed: 6161 additions & 96 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Benchmark: nanprod / nanmedian / nancount — nan-ignoring aggregates on a 100k-element array.
2+
Outputs JSON: {"function": "nancumops_extended", "mean_ms": ..., "iterations": ..., "total_ms": ...}
3+
"""
4+
import json
5+
import time
6+
import math
7+
import numpy as np
8+
import pandas as pd
9+
10+
SIZE = 100_000
11+
WARMUP = 5
12+
ITERATIONS = 50
13+
14+
# Array with ~10% NaN values; small floats to keep product finite
15+
data = np.array([
16+
np.nan if i % 10 == 0 else 1.0 + math.sin(i * 0.001) * 0.001
17+
for i in range(SIZE)
18+
])
19+
s = pd.Series(data)
20+
21+
for _ in range(WARMUP):
22+
np.nanprod(data)
23+
np.nanmedian(data)
24+
np.count_nonzero(~np.isnan(data))
25+
26+
start = time.perf_counter()
27+
for _ in range(ITERATIONS):
28+
np.nanprod(data)
29+
np.nanmedian(data)
30+
np.count_nonzero(~np.isnan(data))
31+
total = (time.perf_counter() - start) * 1000
32+
33+
print(json.dumps({
34+
"function": "nancumops_extended",
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+
"""Benchmark: string_ops_extended — strip, replace, startswith/endswith 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 % 200} " for i in range(ROWS)]
10+
s = pd.Series(data)
11+
12+
for _ in range(WARMUP):
13+
s.str.strip()
14+
s.str.replace("hello", "hi", regex=False)
15+
s.str.startswith("hello")
16+
s.str.endswith("world")
17+
18+
start = time.perf_counter()
19+
for _ in range(ITERATIONS):
20+
s.str.strip()
21+
s.str.replace("hello", "hi", regex=False)
22+
s.str.startswith("hello")
23+
s.str.endswith("world")
24+
total = (time.perf_counter() - start) * 1000
25+
26+
print(json.dumps({
27+
"function": "string_ops_extended",
28+
"mean_ms": total / ITERATIONS,
29+
"iterations": ITERATIONS,
30+
"total_ms": total,
31+
}))

0 commit comments

Comments
 (0)