import time import numpy as np def calculate_execution_metrics(sequential_fn, parallel_fn, img, config): """ Compares timing and performance metrics. """ # Hot run to ensure cache/init doesn't skew small images (optional) # sequential_fn(img, config) # Sequential Test start_seq = time.perf_counter() res_seq = sequential_fn(img, config) time_seq = time.perf_counter() - start_seq # Parallel Test start_par = time.perf_counter() res_par = parallel_fn(img, config) time_par = time.perf_counter() - start_par speedup = time_seq / time_par if time_par > 0 else 1.0 return { "sequential_time": time_seq, "parallel_time": time_par, "speedup": speedup, "result": res_par # Use parallel result as final } def get_image_info(img): """ Returns resolution and channel info. """ h, w, c = img.shape return { "width": w, "height": h, "channels": c, "megapixels": (w * h) / 1e6 }