Skip to content

Instantly share code, notes, and snippets.

@shivankgtm
Created February 29, 2020 04:23
Show Gist options
  • Save shivankgtm/654a5d08dfbffa255e8f09a6bb23ef02 to your computer and use it in GitHub Desktop.
Save shivankgtm/654a5d08dfbffa255e8f09a6bb23ef02 to your computer and use it in GitHub Desktop.
import time
import numpy as np
np_array = np.arange(1, 1000000)
python_list = range(1, 1000000)
np_start = time.time()
result = [i**2 for i in np_array]
np_end = time.time()
print('Total time taken by numpy = ', np_end-np_start)
py_start = time.time()
result = [i**2 for i in python_list]
py_end = time.time()
print('Total time taken by Python = ', py_end-py_start)
#Output:
# Total time taken by numpy = 0.37919187545776367
# Total time taken by Python = 0.3959920406341553
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment