Skip to content

Commit 8bbcb23

Browse files
Iteration 115: Add 6 new benchmark pairs (340 total, +6 vs best 334)
Run: https://github.com/githubnext/tsessebe/actions/runs/24483302039 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 67d0546 commit 8bbcb23

12 files changed

Lines changed: 383 additions & 0 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Benchmark: dt_is_quarter_start_end — is_quarter_start, is_quarter_end 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="1D")
10+
s = pd.Series(dates)
11+
12+
for _ in range(WARMUP):
13+
s.dt.is_quarter_start
14+
s.dt.is_quarter_end
15+
16+
start = time.perf_counter()
17+
for _ in range(ITERATIONS):
18+
s.dt.is_quarter_start
19+
s.dt.is_quarter_end
20+
total = (time.perf_counter() - start) * 1000
21+
22+
print(json.dumps({
23+
"function": "dt_is_quarter_start_end",
24+
"mean_ms": total / ITERATIONS,
25+
"iterations": ITERATIONS,
26+
"total_ms": total,
27+
}))
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Benchmark: dt_year_month_day — dt.year, dt.month, dt.day 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="1D")
10+
s = pd.Series(dates)
11+
12+
for _ in range(WARMUP):
13+
s.dt.year
14+
s.dt.month
15+
s.dt.day
16+
17+
start = time.perf_counter()
18+
for _ in range(ITERATIONS):
19+
s.dt.year
20+
s.dt.month
21+
s.dt.day
22+
total = (time.perf_counter() - start) * 1000
23+
24+
print(json.dumps({
25+
"function": "dt_year_month_day",
26+
"mean_ms": total / ITERATIONS,
27+
"iterations": ITERATIONS,
28+
"total_ms": total,
29+
}))

benchmarks/pandas/bench_ewm_var.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Benchmark: EWM var (span=20) 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(span=20).var()
15+
16+
start = time.perf_counter()
17+
for _ in range(ITERATIONS):
18+
s.ewm(span=20).var()
19+
total = (time.perf_counter() - start) * 1000
20+
21+
print(json.dumps({
22+
"function": "ewm_var",
23+
"mean_ms": total / ITERATIONS,
24+
"iterations": ITERATIONS,
25+
"total_ms": total,
26+
}))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Benchmark: MultiIndex.duplicated() and drop_duplicates() on 100k-pair MultiIndex"""
2+
import json, time
3+
import pandas as pd
4+
5+
ROWS = 100_000
6+
WARMUP = 3
7+
ITERATIONS = 10
8+
9+
# Create a MultiIndex with duplicates (10k unique pairs repeated 10 times)
10+
a = [f"a{i % 100}" for i in range(ROWS)]
11+
b = [i % 1000 for i in range(ROWS)]
12+
tuples = list(zip(a, b))
13+
14+
mi = pd.MultiIndex.from_tuples(tuples)
15+
16+
for _ in range(WARMUP):
17+
mi.duplicated()
18+
mi.drop_duplicates()
19+
20+
start = time.perf_counter()
21+
for _ in range(ITERATIONS):
22+
mi.duplicated()
23+
mi.drop_duplicates()
24+
total = (time.perf_counter() - start) * 1000
25+
26+
print(json.dumps({
27+
"function": "multi_index_duplicated",
28+
"mean_ms": total / ITERATIONS,
29+
"iterations": ITERATIONS,
30+
"total_ms": total,
31+
}))
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Benchmark: MultiIndex.isna(), notna(), dropna() on 100k-pair MultiIndex with some nulls"""
2+
import json, time
3+
import pandas as pd
4+
import numpy as np
5+
6+
ROWS = 100_000
7+
WARMUP = 3
8+
ITERATIONS = 10
9+
10+
# Create a MultiIndex with some null values
11+
a = [None if i % 10 == 0 else f"a{i % 100}" for i in range(ROWS)]
12+
b = [None if i % 20 == 0 else i % 1000 for i in range(ROWS)]
13+
tuples = list(zip(a, b))
14+
15+
mi = pd.MultiIndex.from_tuples(tuples)
16+
17+
for _ in range(WARMUP):
18+
mi.isna()
19+
mi.notna()
20+
mi.dropna()
21+
22+
start = time.perf_counter()
23+
for _ in range(ITERATIONS):
24+
mi.isna()
25+
mi.notna()
26+
mi.dropna()
27+
total = (time.perf_counter() - start) * 1000
28+
29+
print(json.dumps({
30+
"function": "multi_index_isna_dropna",
31+
"mean_ms": total / ITERATIONS,
32+
"iterations": ITERATIONS,
33+
"total_ms": total,
34+
}))
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Benchmark: MultiIndex sort_values and equals on 100k-pair MultiIndex"""
2+
import json, time
3+
import pandas as pd
4+
5+
ROWS = 100_000
6+
WARMUP = 3
7+
ITERATIONS = 10
8+
9+
a = [f"a{i % 100}" for i in range(ROWS)]
10+
b = [i % 1000 for i in range(ROWS)]
11+
tuples = list(zip(a, b))
12+
13+
mi = pd.MultiIndex.from_tuples(tuples)
14+
mi2 = pd.MultiIndex.from_tuples(tuples[:])
15+
16+
for _ in range(WARMUP):
17+
mi.sort_values()
18+
mi.equals(mi2)
19+
20+
start = time.perf_counter()
21+
for _ in range(ITERATIONS):
22+
mi.sort_values()
23+
mi.equals(mi2)
24+
total = (time.perf_counter() - start) * 1000
25+
26+
print(json.dumps({
27+
"function": "multi_index_sort_equals",
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: dt_is_quarter_start_end — is_quarter_start, is_quarter_end on 100k datetime values
3+
*/
4+
import { Series } from "../../src/index.ts";
5+
6+
const ROWS = 100_000;
7+
const WARMUP = 3;
8+
const ITERATIONS = 10;
9+
10+
const now = new Date("2024-01-01").getTime();
11+
const data = Array.from({ length: ROWS }, (_, i) => new Date(now + i * 24 * 3600 * 1000));
12+
const s = new Series({ data });
13+
14+
for (let i = 0; i < WARMUP; i++) {
15+
s.dt.is_quarter_start();
16+
s.dt.is_quarter_end();
17+
}
18+
19+
const start = performance.now();
20+
for (let i = 0; i < ITERATIONS; i++) {
21+
s.dt.is_quarter_start();
22+
s.dt.is_quarter_end();
23+
}
24+
const total = performance.now() - start;
25+
26+
console.log(
27+
JSON.stringify({
28+
function: "dt_is_quarter_start_end",
29+
mean_ms: total / ITERATIONS,
30+
iterations: ITERATIONS,
31+
total_ms: total,
32+
}),
33+
);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Benchmark: dt_year_month_day — dt.year(), dt.month(), dt.day() on 100k datetime values
3+
*/
4+
import { Series } from "../../src/index.ts";
5+
6+
const ROWS = 100_000;
7+
const WARMUP = 3;
8+
const ITERATIONS = 10;
9+
10+
const now = new Date("2024-01-01").getTime();
11+
const data = Array.from({ length: ROWS }, (_, i) => new Date(now + i * 24 * 3600 * 1000));
12+
const s = new Series({ data });
13+
14+
for (let i = 0; i < WARMUP; i++) {
15+
s.dt.year();
16+
s.dt.month();
17+
s.dt.day();
18+
}
19+
20+
const start = performance.now();
21+
for (let i = 0; i < ITERATIONS; i++) {
22+
s.dt.year();
23+
s.dt.month();
24+
s.dt.day();
25+
}
26+
const total = performance.now() - start;
27+
28+
console.log(
29+
JSON.stringify({
30+
function: "dt_year_month_day",
31+
mean_ms: total / ITERATIONS,
32+
iterations: ITERATIONS,
33+
total_ms: total,
34+
}),
35+
);

benchmarks/tsb/bench_ewm_var.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Benchmark: EWM var (span=20) on 100k-element Series
3+
*/
4+
import { Series } from "../../src/index.ts";
5+
6+
const ROWS = 100_000;
7+
const WARMUP = 3;
8+
const ITERATIONS = 10;
9+
10+
const data = Float64Array.from({ length: ROWS }, (_, i) => Math.sin(i * 0.01));
11+
const s = new Series(data);
12+
13+
for (let i = 0; i < WARMUP; i++) {
14+
s.ewm({ span: 20 }).var();
15+
}
16+
17+
const start = performance.now();
18+
for (let i = 0; i < ITERATIONS; i++) {
19+
s.ewm({ span: 20 }).var();
20+
}
21+
const total = performance.now() - start;
22+
23+
console.log(
24+
JSON.stringify({
25+
function: "ewm_var",
26+
mean_ms: total / ITERATIONS,
27+
iterations: ITERATIONS,
28+
total_ms: total,
29+
}),
30+
);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Benchmark: MultiIndex.duplicated() and dropDuplicates() on 100k-pair MultiIndex
3+
*/
4+
import { MultiIndex } from "../../src/index.ts";
5+
6+
const ROWS = 100_000;
7+
const WARMUP = 3;
8+
const ITERATIONS = 10;
9+
10+
// Create a MultiIndex with duplicates (10k unique pairs repeated 10 times)
11+
const a = Array.from({ length: ROWS }, (_, i) => `a${i % 100}`);
12+
const b = Array.from({ length: ROWS }, (_, i) => i % 1000);
13+
const tuples: [string, number][] = a.map((v, i) => [v, b[i]]);
14+
const mi = new MultiIndex({ tuples });
15+
16+
for (let i = 0; i < WARMUP; i++) {
17+
mi.duplicated();
18+
mi.dropDuplicates();
19+
}
20+
21+
const start = performance.now();
22+
for (let i = 0; i < ITERATIONS; i++) {
23+
mi.duplicated();
24+
mi.dropDuplicates();
25+
}
26+
const total = performance.now() - start;
27+
28+
console.log(
29+
JSON.stringify({
30+
function: "multi_index_duplicated",
31+
mean_ms: total / ITERATIONS,
32+
iterations: ITERATIONS,
33+
total_ms: total,
34+
}),
35+
);

0 commit comments

Comments
 (0)