From 6f9170a891485040b5eebf55c6173d63205bd305 Mon Sep 17 00:00:00 2001 From: ilia Date: Fri, 6 Oct 2023 13:19:11 +0300 Subject: [PATCH] edit interpreters readme --- interpreters/README.md | 75 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/interpreters/README.md b/interpreters/README.md index 6500908..8826434 100644 --- a/interpreters/README.md +++ b/interpreters/README.md @@ -2,23 +2,86 @@ ## Testing Code Three functions tested -```python:pure_with_types.py +```python +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_with_types( + 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]]: -```python:pure_no_types.py + 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 -``` +def mandelbrot_no_types( + 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 -```python:np_extended.py +def mandelbrot_np( + 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 ``` ## Tested interpreters - CPython 3.9 - CPython 3.11 - PyPy 3.9 -- Jython **Table of evaluation times in seconds** ![enter image description here](table.png)