only create dataset if needed
1 changed file+20−7
zia_benchmark/src/zia_benchmark/run_benchmarks.pymodified+20−7View file
@@ -63,13 +63,12 @@ def run_benchmarks(
6363 # Run benchmarks for each dataset and algorithm combination
6464 for dataset in datasets:
6565 dataset_tags = dataset.get("tags", [])
66- print(f"\n--- Dataset: {dataset['name']} (tags: {dataset_tags}) ---")
67- # Create dataset once for all algorithms
68- data = dataset["create"]()
69- dtype = str(data.dtype)
70- original_size = len(data.tobytes())
71- print(f"Created dataset: shape={data.shape}, dtype={dtype}")
72- print(f"Original size: {original_size:,} bytes")
66+ print(f"\n*** Dataset: {dataset['name']} (tags: {dataset_tags}) ***")
67+
68+ # data will only be created if needed
69+ data = None
70+ original_size = None
71+ dtype = None
7372
7473 for algorithm in algorithms:
7574 alg_name = algorithm["name"]
@@ -136,10 +135,24 @@ def run_benchmarks(
136135 continue
137136
138137 print(" Running new benchmark...")
138+ if data is None:
139+ # only create data if needed
140+ data = dataset["create"]()
141+ dtype = str(data.dtype)
142+ original_size = len(data.tobytes())
143+ print(f"Created dataset: shape={data.shape}, dtype={dtype}")
144+ print(f"Original size: {original_size:,} bytes")
145+
146+ assert data is not None
147+ assert isinstance(data, np.ndarray)
148+ assert isinstance(original_size, int)
149+ assert isinstance(dtype, str)
139150
140151 def run_timed_trials(operation, *args) -> Tuple[float, float]:
141152 """Run multiple trials of an operation until total time exceeds 1 second.
142153 Returns (median_time, mb_per_sec)"""
154+ assert data is not None
155+ assert isinstance(data, np.ndarray)
143156 times = []
144157 total_time = 0
145158 array_size_mb = data.nbytes / (1024 * 1024) # Convert to MB