#!/usr/bin/env python2.4
"""
Compare accessing elements of list, array and deque
"""

import sys
import time
import array
from collections import deque
    

def testCollection(collection, size):
    """ Test a collection with size items
    
    Get an empty collection, append size items, then delete all items
    one by one, from the first to the last.
    
    Return the time in seconds
    """
    start = time.time()
    
    for i in xrange(size):
        collection.append(i)
    
    while collection:
        del collection[0]
    
    return time.time() - start

   
print """Comparing list, array and deque

size       list       array      deque
-------------------------------------------"""

for size in (10, 1000, 10000, 100000, 200000):
    print '%10d' % size,
    
    for collection in (list(), array.array('i'), deque()):
        print '%10.6f' % testCollection(collection, size),

    print
