Skip to content

Instantly share code, notes, and snippets.

@rsarai
Created October 9, 2019 22:16
Show Gist options
  • Save rsarai/dc60c201ae35e10bd429ed12f10bc8b0 to your computer and use it in GitHub Desktop.
Save rsarai/dc60c201ae35e10bd429ed12f10bc8b0 to your computer and use it in GitHub Desktop.
import time
import random
sorted_array = []
unsorted_array = []
for i in range(0, 1000000):
random_integer = random.randint(0, 1000000)
unsorted_array.append(random_integer)
def process_array(array):
start = time.time()
sum = 0
for i in array:
sum += i
end = time.time()
print(end - start)
process_array(unsorted_array)
# 0.03239941596984863
unsorted_array.sort()
process_array(unsorted_array)
# 0.1422126293182373
@rsarai
Copy link
Author

rsarai commented Oct 23, 2019

import random
import timeit

unsorted_array = []
unsorted_array = [random.randint(0, 1000000) for i in range(0, 1000000)]
unsorted_array.sort()
unsorted_array[:20]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment