import numpy as np

from timeit import Timer

size_of_vec = 1000

def pure_python_version():

X = range(size_of_vec)

Y = range(size_of_vec)

Z = []

for i in range(len(X)):

Z.append(X[i] + Y[i])

def numpy_version():

X = np.arange(size_of_vec)

Y = np.arange(size_of_vec)

Z = X + Y

#timer_obj = Timer("x = x + 1", "x = 0")

timer_obj1 = Timer("pure_python_version()", "from __main__ import pure_python_version")

timer_obj2 = Timer("numpy_version()", "from __main__ import numpy_version")

print(timer_obj1.timeit(10))

print(timer_obj2.timeit(10))

0.0022348780039465055

6.224898970685899e-05

from timeit import Timer

size_of_vec = 1000

def pure_python_version():

X = range(size_of_vec)

Y = range(size_of_vec)

Z = []

for i in range(len(X)):

Z.append(X[i] + Y[i])

def numpy_version():

X = np.arange(size_of_vec)

Y = np.arange(size_of_vec)

Z = X + Y

#timer_obj = Timer("x = x + 1", "x = 0")

timer_obj1 = Timer("pure_python_version()", "from __main__ import pure_python_version")

timer_obj2 = Timer("numpy_version()", "from __main__ import numpy_version")

print(timer_obj1.timeit(10))

print(timer_obj2.timeit(10))

0.0022348780039465055

6.224898970685899e-05