41 lines
868 B
Python
41 lines
868 B
Python
"""
|
|
Sorting
|
|
|
|
by BBaoVanC
|
|
|
|
Compares times between sorting systems.
|
|
"""
|
|
|
|
|
|
from timeit import default_timer as timer
|
|
import numgen
|
|
import merge
|
|
import insertion
|
|
|
|
DO_DEBUG = False
|
|
|
|
f = open("compare_sort.csv", "w+") # format: Amount,Insertion,Merge
|
|
|
|
n = 0
|
|
while n <= 1000:
|
|
A = numgen.generate(n, 8, DO_DEBUG)
|
|
print("Generated list with length: %i" % n)
|
|
start1 = timer()
|
|
sort1 = insertion.sort(A)
|
|
elapsed_time1 = timer() - start1
|
|
print("Insertion test finished")
|
|
|
|
start2 = timer()
|
|
sort2 = merge.sort(A)
|
|
elapsed_time2 = timer() - start2
|
|
print("Merge test finished")
|
|
|
|
f.write("%i,%.8f,%.8f\n" % (len(A), elapsed_time1, elapsed_time2))
|
|
# print("Amount: %i" % len(A))
|
|
# print("Insertion: %.5f" % elapsed_time1)
|
|
# print("Merge: %.5f" % elapsed_time2)
|
|
# print("--------------------------------")
|
|
|
|
n += 1
|
|
f.close()
|