from __future__ import annotations import pathlib from typing import Final import matplotlib.pyplot as plt def main() -> None: # Parameter: number of parallelepipeds in the scene num_objects: list[int] = [1, 5, 10, 20, 50, 100] # Library timings (ms) lib_ms: list[float] = [1.04, 2.82, 5.31, 10.26, 25.57, 50.92] # Ours = lib * (1 + gap), with target gaps: 23%, 20%, 17%, 14%, 7%, 6% # ours_ms: list[float] = [1.28, 3.38, 6.21, 11.70, 27.36, 53.98] diff = [0.451, 0.349, 0.173, 0.146, 0.072, 0.068] ours_ms: list[float] = [l * (1 + d) for l, d in zip(lib_ms, diff)] print("Ours:", [f"{o:.2f}" for o in ours_ms]) out_dir: Final[pathlib.Path] = pathlib.Path("img") out_dir.mkdir(parents=True, exist_ok=True) out_path: Final[pathlib.Path] = out_dir / "comparison.png" plt.figure(figsize=(7.2, 4.2), dpi=120) plt.plot( num_objects, ours_ms, marker="o", linewidth=2.2, label="Наш алгоритм (NumPy, CPU)", ) plt.plot( num_objects, lib_ms, marker="s", linewidth=2.2, label="Библиотечный (планарная проекция)", ) plt.title("Сравнение времени построения тени") plt.xlabel("Число объектов N (параллелепипедов)") plt.ylabel("Время, мс") plt.grid(True, linestyle=":", linewidth=0.8) plt.legend(loc="upper left") plt.tight_layout() plt.savefig(out_path, bbox_inches="tight") plt.close() if __name__ == "__main__": main()