DAS_2024_1/bazunov_andrew_lab_6/main.py

26 lines
583 B
Python
Raw Normal View History

2024-11-28 23:56:00 +04:00
import time
from collections.abc import Callable
from random import random
from matrix import Matrix
_THREADS = 20
def measure_time(func: Callable, *args) -> float:
t1 = time.process_time()
func(*args)
t2 = time.process_time()
return round(t2 - t1, 5)
tests = [i for i in range(1, 10)]
for test in tests:
mt1 = Matrix(size=test, suplyer=random)
t1 = measure_time(lambda: mt1.det())
t5 = measure_time(lambda: mt1.det(threads=5))
t20 = measure_time(lambda: mt1.det(threads=20))
print(f"|{f'{test}x{test}':<16}|{t1:^11}|{t5:^11}|{t20:^12}|")