Skip to content

Instantly share code, notes, and snippets.

@Manikant92
Created July 20, 2018 10:01
Show Gist options
  • Save Manikant92/bda0d6a6beb7c85435f6ba955c10e716 to your computer and use it in GitHub Desktop.
Save Manikant92/bda0d6a6beb7c85435f6ba955c10e716 to your computer and use it in GitHub Desktop.
#As we have generated small data like 1-15, it is fast. But when processing/generating huge amount of data like in millions and trillions
#you need to process fastly. That's when numpy arrays will come useful.
#this is calculate the start time
timestamp1 = time.time()
#generate data in range of 0 to 1 million using numpy arrays
x = np.arange(1000000)
#end time
timestamp2 = time.time()
#time taken to generate 1 million data.
print("This took %.2f seconds" % (timestamp2 - timestamp1))
#This took 0.02 seconds
#lets generate the same data using lists
timestamp1 = time.time()
x = []
for i in range(1000000):
x.append(i)
timestamp2 = time.time()
print("This took %.2f seconds" % (timestamp2 - timestamp1))
#output: This took 0.33 seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment