Skip to content

Commit f08bb3f

Browse files
[Autoloop: perf-comparison] Iteration 416: benchmark QuarterEnd/QuarterBegin/BMonthEnd/BMonthBegin/BYearEnd/BYearBegin offsets
Run: https://github.com/githubnext/tsb/actions/runs/29923579451 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f2d9afa commit f08bb3f

2 files changed

Lines changed: 114 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
Benchmark: Business and Quarter date offsets — QuarterEnd, QuarterBegin,
3+
BMonthEnd, BMonthBegin, BYearEnd, BYearBegin.
4+
Mirrors tsb bench_business_offsets.ts.
5+
Dataset: 5,000 dates; 50 measured iterations.
6+
Outputs JSON: {"function": "business_offsets", "mean_ms": ..., "iterations": ..., "total_ms": ...}
7+
"""
8+
import json
9+
import time
10+
from datetime import datetime, timedelta, timezone
11+
12+
import pandas as pd
13+
from pandas.tseries.offsets import (
14+
BMonthBegin,
15+
BMonthEnd,
16+
BYearBegin,
17+
BYearEnd,
18+
QuarterBegin,
19+
QuarterEnd,
20+
)
21+
22+
SIZE = 5_000
23+
WARMUP = 5
24+
ITERATIONS = 50
25+
26+
q_end = QuarterEnd(1)
27+
q_begin = QuarterBegin(1)
28+
bm_end = BMonthEnd(1)
29+
bm_begin = BMonthBegin(1)
30+
by_end = BYearEnd(1)
31+
by_begin = BYearBegin(1)
32+
33+
base = datetime(2020, 1, 15, tzinfo=timezone.utc)
34+
dates = [base + timedelta(days=i) for i in range(SIZE)]
35+
ts_dates = [pd.Timestamp(d) for d in dates]
36+
37+
for _ in range(WARMUP):
38+
for d in ts_dates[:100]:
39+
d + q_end
40+
d + q_begin
41+
d + bm_end
42+
d + bm_begin
43+
d + by_end
44+
d + by_begin
45+
46+
t0 = time.perf_counter()
47+
for _ in range(ITERATIONS):
48+
for d in ts_dates:
49+
d + q_end
50+
d + q_begin
51+
d + bm_end
52+
d + bm_begin
53+
d + by_end
54+
d + by_begin
55+
total_ms = (time.perf_counter() - t0) * 1000
56+
mean_ms = total_ms / ITERATIONS
57+
58+
print(json.dumps({"function": "business_offsets", "mean_ms": mean_ms, "iterations": ITERATIONS, "total_ms": total_ms}))
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Benchmark: Business and Quarter date offsets — QuarterEnd, QuarterBegin,
3+
* BMonthEnd, BMonthBegin, BYearEnd, BYearBegin.
4+
* Mirrors pandas.tseries.offsets quarter/business-month/business-year classes.
5+
* Dataset: 5,000 dates; 50 measured iterations.
6+
* Outputs JSON: {"function": "business_offsets", "mean_ms": ..., "iterations": ..., "total_ms": ...}
7+
*/
8+
import {
9+
QuarterEnd,
10+
QuarterBegin,
11+
BMonthEnd,
12+
BMonthBegin,
13+
BYearEnd,
14+
BYearBegin,
15+
} from "../../src/index.ts";
16+
17+
const SIZE = 5_000;
18+
const WARMUP = 5;
19+
const ITERATIONS = 50;
20+
21+
const qEnd = new QuarterEnd(1);
22+
const qBegin = new QuarterBegin(1);
23+
const bmEnd = new BMonthEnd(1);
24+
const bmBegin = new BMonthBegin(1);
25+
const byEnd = new BYearEnd(1);
26+
const byBegin = new BYearBegin(1);
27+
28+
const base = new Date(Date.UTC(2020, 0, 15));
29+
const dates = Array.from({ length: SIZE }, (_, i) => new Date(base.getTime() + i * 86_400_000));
30+
31+
for (let i = 0; i < WARMUP; i++) {
32+
for (const d of dates.slice(0, 100)) {
33+
qEnd.apply(d);
34+
qBegin.apply(d);
35+
bmEnd.apply(d);
36+
bmBegin.apply(d);
37+
byEnd.apply(d);
38+
byBegin.apply(d);
39+
}
40+
}
41+
42+
const t0 = performance.now();
43+
for (let i = 0; i < ITERATIONS; i++) {
44+
for (const d of dates) {
45+
qEnd.apply(d);
46+
qBegin.apply(d);
47+
bmEnd.apply(d);
48+
bmBegin.apply(d);
49+
byEnd.apply(d);
50+
byBegin.apply(d);
51+
}
52+
}
53+
const total_ms = performance.now() - t0;
54+
const mean_ms = total_ms / ITERATIONS;
55+
56+
console.log(JSON.stringify({ function: "business_offsets", mean_ms, iterations: ITERATIONS, total_ms }));

0 commit comments

Comments
 (0)