Skip to content

Commit b13e067

Browse files
[Autoloop: perf-comparison] Iteration 417: inferFreq benchmark (6 freq types, 200 dates each, 500 iters)
Run: https://github.com/githubnext/tsb/actions/runs/29971651261 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4860d24 commit b13e067

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Benchmark: pandas.tseries.frequencies.infer_freq — infer frequency from date arrays."""
2+
import json
3+
import time
4+
import pandas as pd
5+
from pandas.tseries.frequencies import infer_freq
6+
7+
WARMUP = 5
8+
ITERATIONS = 500
9+
10+
# Build DatetimeIndex arrays for various frequencies
11+
date_sets = [
12+
pd.date_range("2020-01-01", periods=200, freq="ms"),
13+
pd.date_range("2020-01-01", periods=200, freq="s"),
14+
pd.date_range("2020-01-01", periods=200, freq="min"),
15+
pd.date_range("2020-01-01", periods=200, freq="h"),
16+
pd.date_range("2020-01-01", periods=200, freq="D"),
17+
pd.date_range("2020-01-01", periods=200, freq="W"),
18+
]
19+
20+
for _ in range(WARMUP):
21+
for ds in date_sets:
22+
infer_freq(ds)
23+
24+
start = time.perf_counter()
25+
for _ in range(ITERATIONS):
26+
for ds in date_sets:
27+
infer_freq(ds)
28+
total = (time.perf_counter() - start) * 1000
29+
30+
print(json.dumps({"function": "infer_freq", "mean_ms": total / ITERATIONS, "iterations": ITERATIONS, "total_ms": total}))

benchmarks/tsb/bench_infer_freq.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* Benchmark: inferFreq — infer frequency from an array of regularly-spaced dates.
3+
* Outputs JSON: {"function": "infer_freq", "mean_ms": ..., "iterations": ..., "total_ms": ...}
4+
*/
5+
import { inferFreq } from "../../src/index.js";
6+
7+
const WARMUP = 5;
8+
const ITERATIONS = 500;
9+
10+
// Build date arrays for various frequencies
11+
function makeDates(start: Date, stepMs: number, count: number): Date[] {
12+
const out: Date[] = [];
13+
let t = start.getTime();
14+
for (let i = 0; i < count; i++) {
15+
out.push(new Date(t));
16+
t += stepMs;
17+
}
18+
return out;
19+
}
20+
21+
const MS_DAY = 86_400_000;
22+
const MS_HOUR = 3_600_000;
23+
const MS_MIN = 60_000;
24+
25+
const base = new Date("2020-01-01T00:00:00Z");
26+
const dateSets = [
27+
makeDates(base, 1, 200), // 1ms
28+
makeDates(base, 1000, 200), // 1s
29+
makeDates(base, MS_MIN, 200), // 1min
30+
makeDates(base, MS_HOUR, 200), // 1h
31+
makeDates(base, MS_DAY, 200), // daily
32+
makeDates(base, 7 * MS_DAY, 200), // weekly
33+
];
34+
35+
for (let i = 0; i < WARMUP; i++) {
36+
for (const ds of dateSets) {
37+
inferFreq(ds);
38+
}
39+
}
40+
41+
const start = performance.now();
42+
for (let i = 0; i < ITERATIONS; i++) {
43+
for (const ds of dateSets) {
44+
inferFreq(ds);
45+
}
46+
}
47+
const total = performance.now() - start;
48+
49+
console.log(
50+
JSON.stringify({
51+
function: "infer_freq",
52+
mean_ms: total / ITERATIONS,
53+
iterations: ITERATIONS,
54+
total_ms: total,
55+
}),
56+
);

0 commit comments

Comments
 (0)