from container import Container
from time import time
from stack import Stack
from stack2 import Stack2


def container_cycle(c, size):
    """
    Time how long it takes to perform stack operations on stacks
    of various sizes.

    @param Container c: container to be timed
    @param int size: number of items to initialize the container with.
    @rtype: None
    """
    # Bypass the Stack interface to create a stack of size <size> items,
    # for demonstration purposes. And yes, accessing a private attribute
    # here is definitely cheating!
    c._contents = list(range(size))

    # Use a timer to report how long it takes to add and remove 10000 items
    # on our stack. What value we add should make no difference to the time
    # required, so we arbitrarily add 42.
    start = time()
    for i in range(10000):
        c.add(42)
        c.remove()
    print("Stack({} items) - 10000 add/remove operations in {} seconds"
          .format(n, time() - start))

if __name__ == "__main__":
    L = [Stack(), Stack2()]
    for st in L:
        print("\nCycling through {}".format(st))
        for n in [10000, 100000, 1000000]:
            container_cycle(st, n)
