In [2]:
% matplotlib inline

In [3]:
import numpy as np

In [4]:
from time import time

In [31]:
from tqdm import tqdm
from matplotlib import pyplot as plt

loop = 10000
step = 10

x1_num = []
x1_time = []
x2_num = []
x2_time = []

for i in tqdm(range(1, loop, step)):
    random_v1 = np.random.rand(i)
    random_v2 = np.random.rand(i)

    v1_time_s = time()
    for_val_cnt = 0
    for j in range(0, i):
        for_val_cnt += random_v1[j] * random_v2[j]
    v1_time_e = time()
    x1_time.append(v1_time_e - v1_time_s)
    x1_num.append(i)

    v2_time_s = time()
    random_v1.dot(random_v2)
    v2_time_e = time()
    x2_time.append(v2_time_e - v2_time_s)
    x2_num.append(i)

curve_x1, curve_x2 = plt.plot(x1_num, x1_time, 'r-', x2_num, x2_time, 'b-')
plt.xlabel('$loop num$')
plt.ylabel('$time$')
plt.legend((curve_x1, curve_x2), ('$for$', '$numpy$'))
plt.show()


100%|██████████| 1000/1000 [00:03<00:00, 308.50it/s]

In [ ]: