Created
October 9, 2019 22:16
-
-
Save rsarai/dc60c201ae35e10bd429ed12f10bc8b0 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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import random
import timeit
unsorted_array = []
unsorted_array = [random.randint(0, 1000000) for i in range(0, 1000000)]
unsorted_array.sort()
unsorted_array[:20]