Algorithm performance has always been one of the key factors in solving complex real world use cases. We need efficient algorithms especially in the case of sorting huge amounts of data. In this article, I will walk you through how Bubble, Insertion, Quick and Merge sort algorithms are implemented in Python and Rust programming languages to find out if the programming language does matter in getting the edge in performance.
Before continuing with this article, you should have,
Source Code:
import random
import datetime
def BubbleSortAsc(array):
no_swap = True
while no_swap:
no_swap = False
for position in range(0, len(array)-1):
if array[position] > array[position+1]:
## swap
temp = array[position]
array[position] = array[position+1]
array[position+1] = temp
no_swap = True
To Run:
if __name__ == "__main__":
array = [index for index in range(1, 100001)]
random.shuffle(array)
start = datetime.datetime.now()
BubbleSortAsc(array)
end = datetime.datetime.now()
print("It took: ", (end-start).total_seconds()*1000, "ms to sort")
Performance:
#sorting-algorithms #python-programming #evaluating-technology #performance #rust-programming