def _profile_enqueue(queue_size: int, n: int) -> None: """Report the time taken to perform enqueue operations. Specifically, report the time taken to perform a single Queue.enqueue operation on <n> queues, each of size <queue_size>. (We do this on multiple queues to slow down the trials a little.) """ # TODO: implement this function by following the steps in the comments. # Experiment preparation: make a list containing <n> queues, # each of size <queue_size>. The elements you enqueue don't matter. # You can "cheat" here and set your queue's _items attribute # directly to a list of the appropriate size by writing something like # # queue._items = list(range(queue_size)) # # to save a bit of time in setting up the experiment. # First, make a list containing <n> queues of size <queue_size>. # Second, for each of the <n> queues, enqueue a single item. # (Wrap the code in a Timer block to measure the total time taken.) with Timer('profile enqueue'): queue_list = [] queue = Queue() queue._items = list(range(queue_size)) for i in range(n): queue_list.append(queue) for obj in queue_list: obj.enqueue(1)
def _setup_queues(qsize: int, n: int) -> List[Queue]: """Return a list of <n> queues, each of the given size.""" # Experiment preparation: make a list containing <n> queues, # each of size <qsize>. # You can "cheat" here and set your queue's _items attribute directly # to a list of the appropriate size by writing something like # # queue._items = list(range(qsize)) # # to save a bit of time in setting up the experiment. lst = [] for i in range(n): q = Queue() q._items = list(range(qsize)) lst.append(q) return lst
def _profile_dequeue(queue_size: int, n: int) -> None: """Report the time taken to perform enqueue operations. Specifically, report the time taken to perform a single Queue.enqueue operation on <n> queues, each of size <queue_size>. (We do this on multiple queues to slow down the trials a little.) """ # TODO: implement this function in a similar way to _profile_enqueue. # Experiment preparation: make a list containing <n> queues, # each of size <queue_size>. # You can "cheat" here and set your queue's _items attribute # directly to a list of the appropriate size by writing something like # # queue._items = list(range(queue_size)) # # to save a bit of time in setting up the experiment. with Timer('profile dequeue'): queue_list = [] queue = Queue() queue._items = list(range(queue_size)) for i in range(n): queue_list.append(queue) for obj in queue_list: obj.dequeue()