from timeit import Timer from PriorityQueue_linear import PriorityQueue from random import randint,shuffle #For use in a minute. This wrapper code will add a list of data to a priority queue def repetitiveAdd(the_pq,the_new_data): for val in the_new_data: the_pq.enqueue(val) for n in [1000,2000,4000,10000]: #Set up a priority queue with the first n multiples of 10 #Notice that this means that the priority queue starts with n widely scattered items pq = PriorityQueue() for x in range(10,10*n,10): pq.enqueue(x) #Now create a list of the 1000 random numbers between 0 and the largest number already in the queue (10*n) data = [] for x in range(500): data.append(randint(1,10*n)) #Now time how long it takes to add the 500 items into the pre-existing priority queue t1 = Timer("repetitiveAdd(pq,data)", "from __main__ import repetitiveAdd,pq,data") print(f"Adding 500 numbers to a length {n} priority queue: {t1.timeit(number=1):7.5f} sec")