Код: Выделить всё
# Set the size of the matrices
size = 10000
# Generate a random 10000x10000 matrix with NumPy
np_array = np.random.rand(size, size)
# Generate a random 10000x10000 matrix with PyTorch
torch_tensor = torch.rand(size, size)
# Generate a random 10000x10000 matrix with TinyGrad
tg_tensor = Tensor.rand(size, size)
# Benchmark NumPy
start_np = time.time()
np_result = np_array @ np_array # Matrix multiplication
np_time = time.time() - start_np
print(f"NumPy Time: {np_time:.6f} seconds")
# Benchmark PyTorch
start_torch = time.time()
torch_result = torch_tensor @ torch_tensor # Matrix multiplication
torch_time = time.time() - start_torch
print(f"PyTorch Time: {torch_time:.6f} seconds")
# Benchmark TinyGrad
start_tg = time.time()
tg_result = tg_tensor @ tg_tensor # Matrix multiplication
tg_time = time.time() - start_tg
print(f"TinyGrad Time: {tg_time:.6f} seconds")
Код: Выделить всё
NumPy Time: 11.977072 seconds PyTorch Time: 7.905509 seconds TinyGrad Time: 0.000607 seconds
Подробнее здесь: https://stackoverflow.com/questions/791 ... rix-multip