Created
February 29, 2020 04:23
-
-
Save shivankgtm/654a5d08dfbffa255e8f09a6bb23ef02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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