(rows_per_symbol: int, symbols: int, iterations: int)
| 170 | |
| 171 | |
| 172 | def run_benchmarks(rows_per_symbol: int, symbols: int, iterations: int) -> dict[str, Any]: |
| 173 | symbol_names = [f"SYM{i}" for i in range(symbols)] |
| 174 | base = make_dataset(rows_per_symbol, symbol_names) |
| 175 | total_rows = base.height |
| 176 | base_bytes = _estimate_df_bytes(base) |
| 177 | |
| 178 | # Warm-up to stabilize lazy-plan compile and allocation effects. |
| 179 | clean_warm = openquant.data.clean_ohlcv(base) |
| 180 | _ = openquant.data.data_quality_report(base) |
| 181 | _ = openquant.data.align_calendar(clean_warm, interval="1m") |
| 182 | |
| 183 | clean = openquant.data.clean_ohlcv(base) |
| 184 | clean_rows = clean.height |
| 185 | clean_bytes = _estimate_df_bytes(clean) |
| 186 | |
| 187 | function_stats: list[BenchStats] = [ |
| 188 | _measure( |
| 189 | name="clean_ohlcv", |
| 190 | rows=total_rows, |
| 191 | bytes_estimate=base_bytes, |
| 192 | iterations=iterations, |
| 193 | fn=lambda: openquant.data.clean_ohlcv(base), |
| 194 | ), |
| 195 | _measure( |
| 196 | name="data_quality_report", |
| 197 | rows=total_rows, |
| 198 | bytes_estimate=base_bytes, |
| 199 | iterations=iterations, |
| 200 | fn=lambda: openquant.data.data_quality_report(base), |
| 201 | ), |
| 202 | _measure( |
| 203 | name="align_calendar", |
| 204 | rows=clean_rows, |
| 205 | bytes_estimate=clean_bytes, |
| 206 | iterations=iterations, |
| 207 | fn=lambda: openquant.data.align_calendar(clean, interval="1m"), |
| 208 | ), |
| 209 | ] |
| 210 | |
| 211 | io_stats: list[BenchStats] = [] |
| 212 | with TemporaryDirectory(prefix="openquant_bench_") as tmp: |
| 213 | tmp_dir = Path(tmp) |
| 214 | csv_path = tmp_dir / "bench_ohlcv.csv" |
| 215 | pq_path = tmp_dir / "bench_ohlcv.parquet" |
| 216 | base.write_csv(csv_path) |
| 217 | base.write_parquet(pq_path) |
| 218 | |
| 219 | # Warm-up file paths. |
| 220 | _ = openquant.data.load_ohlcv(csv_path) |
| 221 | _ = openquant.data.load_ohlcv(pq_path) |
| 222 | |
| 223 | io_stats.append( |
| 224 | _measure( |
| 225 | name="load_ohlcv_csv", |
| 226 | rows=total_rows, |
| 227 | bytes_estimate=csv_path.stat().st_size, |
| 228 | iterations=iterations, |
| 229 | fn=lambda: openquant.data.load_ohlcv(csv_path), |
no test coverage detected