File size: 1,041 Bytes
1f765c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
    }