diff --git a/.gitignore b/.gitignore index fbca8b3..7b6e3e5 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,10 @@ share/python-wheels/ *.egg MANIFEST devenv/ +time_execution/3_9_cpython/ +time_execution/3_11_cpython/ +time_execution/pypy3.9-v7.3.13-linux64/ +time_execution/venv-pypy/ # PyInstaller # Usually these files are written by a python script from a template diff --git a/hw1/LICENSE b/LICENSE similarity index 100% rename from hw1/LICENSE rename to LICENSE diff --git a/hw1/README.md b/README.md similarity index 100% rename from hw1/README.md rename to README.md diff --git a/hw1/controls/__init__.py b/controls/__init__.py similarity index 100% rename from hw1/controls/__init__.py rename to controls/__init__.py diff --git a/hw1/doc/Makefile b/doc/Makefile similarity index 100% rename from hw1/doc/Makefile rename to doc/Makefile diff --git a/hw1/doc/make.bat b/doc/make.bat similarity index 100% rename from hw1/doc/make.bat rename to doc/make.bat diff --git a/hw1/doc/source/conf.py b/doc/source/conf.py similarity index 100% rename from hw1/doc/source/conf.py rename to doc/source/conf.py diff --git a/hw1/doc/source/controls.rst b/doc/source/controls.rst similarity index 100% rename from hw1/doc/source/controls.rst rename to doc/source/controls.rst diff --git a/hw1/doc/source/index.rst b/doc/source/index.rst similarity index 100% rename from hw1/doc/source/index.rst rename to doc/source/index.rst diff --git a/hw1/doc/source/make.bat b/doc/source/make.bat similarity index 100% rename from hw1/doc/source/make.bat rename to doc/source/make.bat diff --git a/hw1/setup.py b/setup.py similarity index 100% rename from hw1/setup.py rename to setup.py diff --git a/time_execution/mandelbrot.py b/time_execution/mandelbrot.py new file mode 100644 index 0000000..854c229 --- /dev/null +++ b/time_execution/mandelbrot.py @@ -0,0 +1,81 @@ +def linspace(start, stop, n): + if n == 1: + yield stop + return + h = (stop - start) / (n - 1) + for i in range(n): + yield start + h * i + +def mandelbrot_1(pmin = -2.5, pmax= 1.5, qmin = -2, qmax= 2, + ppoints = 200, qpoints = 200, max_iterations = 300, infinity_border = 100): + image = [[0 for i in range(qpoints)] for j in range(ppoints)] + for ip, p in enumerate(linspace(pmin, pmax, ppoints)): + for iq, q in enumerate(linspace(qmin, qmax, qpoints)): + c = p + 1j * q + z = 0 + for k in range(max_iterations): + z = z ** 2 + c + if abs(z) > infinity_border: + image[ip][iq] = 1 + break + return image + +def linspace(start, stop, n): + if n == 1: + yield stop + return + h = (stop - start) / (n - 1) + for i in range(n): + yield start + h * i + +def mandelbrot_2(pmin: float = -2.5, pmax: float = 1.5, qmin: float = -2, qmax: float = 2, + ppoints: int = 200, qpoints: int = 200, max_iterations: int = 300, infinity_border: float = 100) -> list[list[int]]: + + image: list[list[int]] = [[0 for i in range(qpoints)] for j in range(ppoints)] + for ip, p in enumerate(linspace(pmin, pmax, ppoints)): + for iq, q in enumerate(linspace(qmin, qmax, qpoints)): + c: complex = p + 1j * q + z: complex = 0 + for k in range(max_iterations): + z = z ** 2 + c + if abs(z) > infinity_border: + image[ip][iq] = 1 + break + return image + +import numpy as np + +def mandelbrot_3(pmin = -2.5, pmax = 1.5, qmin = -2, qmax = 2, + ppoints = 200, qpoints = 200, max_iterations = 300, infinity_border= 100): + + image = np.zeros((ppoints, qpoints)) + + for ip, p in enumerate(np.linspace(pmin, pmax, ppoints)): + for iq, q in enumerate(np.linspace(qmin, qmax, qpoints)): + c = p + 1j * q + z = 0 + for k in range(max_iterations): + z = z ** 2 + c + if abs(z) > infinity_border: + + image[ip, iq] = 1 + break + return image + + +import time +if __name__ == '__main__': + tic = time.perf_counter_ns() + image = mandelbrot_1() + toc = time.perf_counter_ns() + print((toc - tic)/1_000_000_000, "s - checked_1") + + tic = time.perf_counter_ns() + image = mandelbrot_2() + toc = time.perf_counter_ns() + print((toc - tic)/1_000_000_000, "s - checked_2") + + tic = time.perf_counter_ns() + image = mandelbrot_3() + toc = time.perf_counter_ns() + print((toc - tic)/1_000_000_000, "s - checked_3")