def datos(numero): lista_N=[2,5,10,12,15,20,30,40,45,50,55,60,75,100,125,160,200,250,350,500,600,800,1000] lista_final_tiempo=[] archivo_str='datos_'+str(numero)+'.txt' archivo=open(archivo_str,'w') lista_tiempo=[] for N in lista_N: A = np.random.rand(N,N) B = np.random.rand(N,N) t1 = perf_counter() C=mimatmul(A,B) t2 = perf_counter() dt = t2 - t1 palabra=str(str(dt)+','+str(N)+'\n') archivo.write(palabra) lista_tiempo.append(dt) archivo.flush() archivo.close()
from time import perf_counter import matplotlib.pyplot as plt from mimatmul import mimatmul Corridas = 10 for k in range(Corridas): N = [ 2, 5, 10, 12, 15, 20, 30, 40, 45, 50, 55, 60, 75, 100, 125, 160, 200, 250, 350, 500, 600 ] #,800,1000,2000,5000,10000] memoria = [] tiempos = [] for i in range(len(N)): A = matrix(rand(N[i], N[i])) B = matrix(rand(N[i], N[i])) t1 = perf_counter() C = mimatmul(A, B) t2 = perf_counter() dt = t2 - t1 tam = 3 * (N[i]**2) * 8 tiempos.append(dt) memoria.append(tam) a = open(f"matmul{k}.txt", "w") for i in range(len(N)): a.write(f"{N[i]} {tiempos[i]} {memoria[i]}.\n") a.close() Tcorridas = [] Mcorridas = [] for i in range(Corridas): t = [] m = []
from mimatmul import mimatmul i = 1 while i <= 10: lista = [] listamem = [] Ns = [ 1, 2, 3, 4, 6, 8, 10, 12, 14, 16, 18, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 200, 500, 1000 ] for N in Ns: A = matrix(rand(N, N)) B = matrix(rand(N, N)) t1 = perf_counter() C = mimatmul(A, B, N) t2 = perf_counter() dt = t2 - t1 size = 3 * (N**2) * 8 lista.append(dt) listamem.append(size) x = [ "", "", "", "", "", "", "10", "", "", "", "", "20", "", "", "", "", "", "50", "", "", "", "", "100", "200", "500", "1000" ] x1 = ["", "", "", "", "", "", "", "", "", "", "", "", ""] y = [0.1e-3, 1e-3, 1e-2, 0.1, 1., 10, 60, 60 * 10, 60 * 60] ejey = [ "0.1 ms", "1 ms", "10 ms", "0.1 s", "1 s", "10 s", "1 min", "10 min", "1 h"
] Ncorridas = 10 for i in range(Ncorridas): fid = open(f"matmul{i}.txt", "w") dts = [] #timepo que se demora para cada matriz de tamaño N mem = [] # memoria que usa para cada matriz de tamaño N for N in Ns: print(f"N={N}") A = rand(N, N) B = rand(N, N) t1 = perf_counter() mimatmul(A, B) t2 = perf_counter() dt = t2 - t1 size = 3 * (N**2) * 8 dts.append(dt) mem.append(size) fid.write(f"{N} {dt} {size} \n") print(f"Tiempo transcurrido = {dt} s") print(f"Memoria usada = {size} bytes") fid.flush()
datos = open("datos2_corrida9.txt", "w") N = [ 2, 5, 10, 12, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90, 100, 125, 150, 175, 200, 300, 400, 500, 650, 800, 1000 ] for n in N: print(f"N = {n}") A = rand(n, n) B = rand(n, n) result = np.zeros(shape=(n, n)) t1 = perf_counter() mimatmul(A, B, result) t2 = perf_counter() dt = t2 - t1 ram = 3 * (n**2) * 8 dts.append(dt) mem.append(ram) datos.write(f"{n} {dt} {ram}\n") print(f"Tiempo transcurrido = {dt} s") print(f"Memoria RAM usada = {ram} bytes") datos.flush()