Skip to content

Commit 53b717c

Browse files
committed
Show cold-row lines as soon as they are produced
1 parent 116d28c commit 53b717c

1 file changed

Lines changed: 44 additions & 12 deletions

File tree

bench/indexing/index_query_bench.py

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import os
1313
import re
1414
import statistics
15+
import sys
1516
import tempfile
1617
import time
1718
from pathlib import Path
@@ -161,7 +162,9 @@ def ordered_ids_from_positions(positions: np.ndarray, size: int, dtype: np.dtype
161162
raise ValueError(f"unsupported dtype for benchmark: {dtype}")
162163

163164

164-
def fill_ids(ids: np.ndarray, ordered_ids: np.ndarray, dist: str, rng: np.random.Generator, block_len: int) -> None:
165+
def fill_ids(
166+
ids: np.ndarray, ordered_ids: np.ndarray, dist: str, rng: np.random.Generator, block_len: int
167+
) -> None:
165168
size = ids.shape[0]
166169
if dist == "sorted":
167170
ids[:] = ordered_ids
@@ -199,10 +202,14 @@ def format_geometry_value(value: int | None) -> str:
199202
return "auto" if value is None else f"{value:,}"
200203

201204

202-
def resolve_geometry(shape: tuple[int, ...], dtype: np.dtype, chunks: int | None, blocks: int | None) -> tuple[int, int]:
205+
def resolve_geometry(
206+
shape: tuple[int, ...], dtype: np.dtype, chunks: int | None, blocks: int | None
207+
) -> tuple[int, int]:
203208
chunk_spec = None if chunks is None else (chunks,)
204209
block_spec = None if blocks is None else (blocks,)
205-
resolved_chunks, resolved_blocks = blosc2.compute_chunks_blocks(shape, chunk_spec, block_spec, dtype=dtype)
210+
resolved_chunks, resolved_blocks = blosc2.compute_chunks_blocks(
211+
shape, chunk_spec, block_spec, dtype=dtype
212+
)
206213
return int(resolved_chunks[0]), int(resolved_blocks[0])
207214

208215

@@ -285,7 +292,9 @@ def build_persistent_array(
285292
return arr
286293

287294

288-
def base_array_path(size_dir: Path, size: int, dist: str, id_dtype: np.dtype, chunks: int | None, blocks: int | None) -> Path:
295+
def base_array_path(
296+
size_dir: Path, size: int, dist: str, id_dtype: np.dtype, chunks: int | None, blocks: int | None
297+
) -> Path:
289298
return (
290299
size_dir
291300
/ f"size_{size}_{dist}_{dtype_token(id_dtype)}.{DATASET_LAYOUT_VERSION}.{geometry_token(chunks, blocks)}.b2nd"
@@ -512,7 +521,18 @@ def benchmark_size(
512521
for kind in kinds:
513522
idx_arr, build_time = _open_or_build_indexed_array(
514523
indexed_array_path(
515-
size_dir, size, dist, kind, optlevel, id_dtype, in_mem, chunks, blocks, codec, clevel, nthreads
524+
size_dir,
525+
size,
526+
dist,
527+
kind,
528+
optlevel,
529+
id_dtype,
530+
in_mem,
531+
chunks,
532+
blocks,
533+
codec,
534+
clevel,
535+
nthreads,
516536
),
517537
size,
518538
dist,
@@ -813,6 +833,15 @@ def run_benchmarks(
813833
f"index_clevel={'auto' if clevel is None else clevel}, "
814834
f"index_nthreads={'auto' if nthreads is None else nthreads}"
815835
)
836+
cold_widths = progress_widths(COLD_COLUMNS, sizes, dists, kinds, id_dtype)
837+
print()
838+
print("Cold Query Table")
839+
print_table_header(COLD_COLUMNS, cold_widths)
840+
841+
def cold_progress_callback(row: dict) -> None:
842+
print_table_row(row, COLD_COLUMNS, cold_widths)
843+
sys.stdout.flush()
844+
816845
for dist in dists:
817846
for size in sizes:
818847
size_results = benchmark_size(
@@ -831,12 +860,9 @@ def run_benchmarks(
831860
clevel,
832861
nthreads,
833862
kinds,
863+
cold_row_callback=cold_progress_callback,
834864
)
835865
all_results.extend(size_results)
836-
cold_widths = table_widths(all_results, COLD_COLUMNS)
837-
print()
838-
print("Cold Query Table")
839-
print_table(all_results, COLD_COLUMNS, cold_widths)
840866
if repeats > 0:
841867
measure_warm_queries(all_results, repeats)
842868
warm_widths = table_widths(all_results, WARM_COLUMNS)
@@ -855,7 +881,9 @@ def _format_row(cells: list[str], widths: list[int]) -> str:
855881
return " ".join(cell.ljust(width) for cell, width in zip(cells, widths, strict=True))
856882

857883

858-
def _table_rows(results: list[dict], columns: list[tuple[str, callable]]) -> tuple[list[str], list[list[str]], list[int]]:
884+
def _table_rows(
885+
results: list[dict], columns: list[tuple[str, callable]]
886+
) -> tuple[list[str], list[list[str]], list[int]]:
859887
headers = [header for header, _ in columns]
860888
widths = [len(header) for header in headers]
861889
rows = [[formatter(result) for _, formatter in columns] for result in results]
@@ -864,7 +892,9 @@ def _table_rows(results: list[dict], columns: list[tuple[str, callable]]) -> tup
864892
return headers, rows, widths
865893

866894

867-
def print_table(results: list[dict], columns: list[tuple[str, callable]], widths: list[int] | None = None) -> None:
895+
def print_table(
896+
results: list[dict], columns: list[tuple[str, callable]], widths: list[int] | None = None
897+
) -> None:
868898
headers, rows, computed_widths = _table_rows(results, columns)
869899
widths = computed_widths if widths is None else widths
870900
print(_format_row(headers, widths))
@@ -881,7 +911,9 @@ def print_table_header(columns: list[tuple[str, callable]], widths: list[int] |
881911
print(_format_row(["-" * width for width in widths], widths))
882912

883913

884-
def print_table_row(result: dict, columns: list[tuple[str, callable]], widths: list[int] | None = None) -> None:
914+
def print_table_row(
915+
result: dict, columns: list[tuple[str, callable]], widths: list[int] | None = None
916+
) -> None:
885917
cells = [formatter(result) for _, formatter in columns]
886918
if widths is None:
887919
widths = [max(len(header), len(cell)) for (header, _), cell in zip(columns, cells, strict=True)]

0 commit comments

Comments
 (0)