Jan-25-2022, 08:16 AM
I was not fast enough
Try this for example (have a look to "print" structure)
Try this for example (have a look to "print" structure)
import time import numpy import array N=100000000 # # 8 bytes size int # a = array.array('q') # for i in range(N): # a.append(i); # b = array.array('q') # for i in range(N, 2*N): # b.append(i) a = numpy.arange(N) b = numpy.arange(N, 2*N) # classic dot product of vectors implementation tic = time.process_time() dot = 0; for i in range(N): dot += a[i] * b[i] toc = time.process_time() print(f"dot_product = {dot}") print(f"Classic Computation time = {1000*(toc - tic )}ms") n_tic = time.process_time() n_dot_product = numpy.dot(a, b) ## or n_dot_product = a @ b n_toc = time.process_time() print(f"\nn_dot_product = {(n_dot_product)}") print(f"Vec Computation time = {1000*(n_toc - n_tic )} ms") print(f"Difference on the dot product results = {numpy.abs(n_dot_product - dot)}")