|
| 1 | +import sys |
| 2 | +from os import path |
| 3 | +from subprocess import run |
| 4 | +from time import perf_counter |
| 5 | + |
| 6 | +import matplotlib.pyplot as plt |
| 7 | +from cpuinfo import get_cpu_info |
| 8 | + |
| 9 | +VERSIONS = ["0.1.6", "0.1.11", "0.2.1", "0.2.5", "0.3.2", "0.4.0", "0.5.1", "0.6.0", "0.7.0", "0.7.2", "0.8.0", "0.9.0"] |
| 10 | +N_ITER_SMALL = 100 |
| 11 | +N_ITER_LARGE = 50 |
| 12 | + |
| 13 | + |
| 14 | +def measure_decode(image, n_iterations, decode_threads=4): |
| 15 | + measure_file = path.join(path.dirname(path.abspath(__file__)), "measure_decode.py") |
| 16 | + cmd = f"{sys.executable} {measure_file} {n_iterations} {image} {decode_threads}".split() |
| 17 | + start_time = perf_counter() |
| 18 | + run(cmd, check=True) |
| 19 | + total_time = perf_counter() - start_time |
| 20 | + return total_time / n_iterations |
| 21 | + |
| 22 | + |
| 23 | +def plot_large_by_threads(clr, n_threads): |
| 24 | + plt.plot( |
| 25 | + "0.9.0", |
| 26 | + measure_decode("image_large.heic", N_ITER_LARGE, decode_threads=n_threads), |
| 27 | + color=clr, |
| 28 | + label=f"n_threads={n_threads}", |
| 29 | + marker="x", |
| 30 | + ) |
| 31 | + |
| 32 | + |
| 33 | +if __name__ == "__main__": |
| 34 | + tests_images_path = path.join(path.dirname(path.dirname(path.abspath(__file__))), "tests/images/heif_other") |
| 35 | + arrow_image_path = path.join(tests_images_path, "arrow.heic") |
| 36 | + cat_image_path = path.join(tests_images_path, "cat.hif") |
| 37 | + arrow_image_results = [] |
| 38 | + cat_image_results = [] |
| 39 | + small_image_results = [] |
| 40 | + large_image_results = [] |
| 41 | + for i, v in enumerate(VERSIONS): |
| 42 | + run(f"{sys.executable} -m pip install pillow-heif=={v}".split(), check=True) |
| 43 | + arrow_image_results.append(measure_decode(arrow_image_path, N_ITER_SMALL)) |
| 44 | + cat_image_results.append(measure_decode(cat_image_path, N_ITER_SMALL)) |
| 45 | + small_image_results.append(measure_decode("image_small.heic", N_ITER_SMALL)) |
| 46 | + large_image_results.append(measure_decode("image_large.heic", N_ITER_LARGE)) |
| 47 | + fig, ax = plt.subplots() |
| 48 | + ax.plot(VERSIONS, arrow_image_results, label="arrow image") |
| 49 | + ax.plot(VERSIONS, cat_image_results, label="cat image") |
| 50 | + ax.plot(VERSIONS, small_image_results, label="small image") |
| 51 | + ax.plot(VERSIONS, large_image_results, label="large image") |
| 52 | + colour = plt.gca().lines[-1].get_color() |
| 53 | + plot_large_by_threads(colour, 1) |
| 54 | + plot_large_by_threads(colour, 2) |
| 55 | + plot_large_by_threads(colour, 8) |
| 56 | + plt.ylabel("time to decode(s)") |
| 57 | + if sys.platform.lower() == "darwin": |
| 58 | + _os = "macOS" |
| 59 | + elif sys.platform.lower() == "win32": |
| 60 | + _os = "Windows" |
| 61 | + else: |
| 62 | + _os = "Linux" |
| 63 | + plt.xlabel(f"{_os} - {get_cpu_info()['brand_raw']}") |
| 64 | + ax.legend() |
| 65 | + plt.savefig(f"results_decode_{_os}.png") |
0 commit comments