Make LM1 (some part) and update README.md
This commit is contained in:
parent
075f413df6
commit
c7b9ea3e0e
13
LW1/README.md
Normal file
13
LW1/README.md
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Results
|
||||||
|
## Function execution time measurement
|
||||||
|
|Interpitator | Pure Python without type annotations | Pure Python with type annotations | Python + numpy|
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
|CPython 3.9 | 0.255727898 s | 0.250940687 s | 0.333585421 s|
|
||||||
|
|CPython 3.11 | 0.178182069 s | 0.18051334 s | 0.312025812 s |
|
||||||
|
|Latest PyPy for Python 3.9 | 0.039385466 s | 0.312025812 s | 1.51180428 s |
|
||||||
|
## Measuring the execution time of a function along with running the script and interpreter
|
||||||
|
|Interpitator | Pure Python without type annotations | Pure Python with type annotations | Python + numpy |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
|CPython 3.9 | **real**: 0m0,260s; **user**: 0m0,260s; **sys**: 0m0,000s | **real**: 0m0,262s; **user**: 0m0,262s; **sys**: 0m0,000s | **real**: 0m0,458s; **user**: 0m0,644s; **sys**: 0m0,712s |
|
||||||
|
|CPython 3.11 | **real**: 0m0,191s; **user**: 0m0,191s; **sys**: 0m0,000s | **real**: 0m0,191s; **user**: 0m0,190s; **sys**: 0m0,000s | **real**: 0m0,426s; **user**: 0m0,533s; **sys**: 0m0,794s |
|
||||||
|
|Latest PyPy for Python 3.9 | **real**: 0m0,065s; **user**: 0m0,065s; **sys**: 0m0,000s | **real**: 0m0,064s; **user**: 0m0,064s; **sys**: 0m0,000s | **real**: 0m1,863s; **user**: 0m2,072s; **sys**: 0m0,687s |
|
24
LW1/python_and_numpy.py
Normal file
24
LW1/python_and_numpy.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import time
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
def mandelbrot(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
|
||||||
|
|
||||||
|
tic = time.perf_counter_ns()
|
||||||
|
image = mandelbrot()
|
||||||
|
toc = time.perf_counter_ns()
|
||||||
|
print((toc - tic)/1_000_000_000, "s")
|
28
LW1/with_annotation.py
Normal file
28
LW1/with_annotation.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import time
|
||||||
|
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(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
|
||||||
|
|
||||||
|
tic = time.perf_counter_ns()
|
||||||
|
image = mandelbrot()
|
||||||
|
toc = time.perf_counter_ns()
|
||||||
|
print((toc - tic)/1_000_000_000, "s")
|
27
LW1/without_annotation.py
Normal file
27
LW1/without_annotation.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import time
|
||||||
|
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(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
|
||||||
|
|
||||||
|
tic = time.perf_counter_ns()
|
||||||
|
image = mandelbrot()
|
||||||
|
toc = time.perf_counter_ns()
|
||||||
|
print((toc - tic)/1_000_000_000, "s")
|
@ -15,7 +15,7 @@ pip install -r requirements.txt
|
|||||||
pip install -e .
|
pip install -e .
|
||||||
```
|
```
|
||||||
|
|
||||||
4. To generate documentation in HTML format, you need to run the following commands:
|
5. To generate documentation in HTML format, you need to run the following commands:
|
||||||
```
|
```
|
||||||
cd ./docs
|
cd ./docs
|
||||||
make html
|
make html
|
||||||
|
Loading…
Reference in New Issue
Block a user