|
| 1 | +/** |
| 2 | + * Benchmark: resample_std_var_size — SeriesResampler.std(), .var(), .size() on hourly bins. |
| 3 | + * |
| 4 | + * Mirrors pandas: pd.Series.resample("H").std() / .var() / .size() |
| 5 | + * std() computes standard deviation per bin, var() computes variance, |
| 6 | + * size() returns the count per bin. |
| 7 | + * |
| 8 | + * Outputs JSON: {"function": "resample_std_var_size", "mean_ms": ..., "iterations": ..., "total_ms": ...} |
| 9 | + */ |
| 10 | +import { Series, resampleSeries } from "../../src/index.ts"; |
| 11 | + |
| 12 | +const SIZE = 50_000; |
| 13 | +const WARMUP = 3; |
| 14 | +const ITERATIONS = 30; |
| 15 | + |
| 16 | +const base = new Date("2020-01-01T00:00:00Z").getTime(); |
| 17 | +const idx = Array.from({ length: SIZE }, (_, i) => new Date(base + i * 60_000)); |
| 18 | +const data = Array.from({ length: SIZE }, (_, i) => Math.sin(i * 0.05) * 50 + (i % 60) * 0.5); |
| 19 | + |
| 20 | +const s = new Series({ data, index: idx }); |
| 21 | + |
| 22 | +for (let i = 0; i < WARMUP; i++) { |
| 23 | + resampleSeries(s, "H").std(); |
| 24 | + resampleSeries(s, "H").var(); |
| 25 | + resampleSeries(s, "H").size(); |
| 26 | +} |
| 27 | + |
| 28 | +const times: number[] = []; |
| 29 | +for (let i = 0; i < ITERATIONS; i++) { |
| 30 | + const t0 = performance.now(); |
| 31 | + resampleSeries(s, "H").std(); |
| 32 | + resampleSeries(s, "H").var(); |
| 33 | + resampleSeries(s, "H").size(); |
| 34 | + times.push(performance.now() - t0); |
| 35 | +} |
| 36 | +const total = times.reduce((a, b) => a + b, 0); |
| 37 | +console.log( |
| 38 | + JSON.stringify({ |
| 39 | + function: "resample_std_var_size", |
| 40 | + mean_ms: total / ITERATIONS, |
| 41 | + iterations: ITERATIONS, |
| 42 | + total_ms: total, |
| 43 | + }), |
| 44 | +); |
0 commit comments