30 lines
1001 B
Python
30 lines
1001 B
Python
|
import time
|
||
|
import random
|
||
|
|
||
|
from DAS_2024_1.kurushina_ksenia_lab_5.parallel import matrix_multiply_parallel
|
||
|
from DAS_2024_1.kurushina_ksenia_lab_5.sequential import matrix_multiply_sequential
|
||
|
|
||
|
|
||
|
def generate_matrix(size):
|
||
|
return [[random.randint(0, 10) for _ in range(size)] for _ in range(size)]
|
||
|
|
||
|
def benchmark(matrix_size, num_threads):
|
||
|
A = generate_matrix(matrix_size)
|
||
|
B = generate_matrix(matrix_size)
|
||
|
|
||
|
start = time.time()
|
||
|
matrix_multiply_sequential(A, B)
|
||
|
sequential_time = time.time() - start
|
||
|
|
||
|
start = time.time()
|
||
|
matrix_multiply_parallel(A, B, num_threads)
|
||
|
parallel_time = time.time() - start
|
||
|
|
||
|
print(f"Размер матрицы: {matrix_size}x{matrix_size}")
|
||
|
print(f"Последовательное время: {sequential_time:.5f} сек")
|
||
|
print(f"Параллельное время ({num_threads} потоков): {parallel_time:.5f} сек")
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
for size in [100, 300, 500]:
|
||
|
benchmark(size, num_threads=4)
|