print('%5s\t%5s\t%10s\t%10s' % ('offset', 'length', 'islice', 'compr'))
for offset in range(0, size - 2000, 2000):
    for length in range(10, 2000, 40):
        t1 = timeit.timeit('list(itertools.islice(d, %d, %d))' % (offset, 
            offset + length), setup, number=repeats)
t2 = timeit.timeit('[d[i] for i in range(%d, %d)]' % (offset, offset +
    length), setup, number=repeats)
print('%5d\t%5d\t%10.3f\t%10.3f' % (offset, length, t1 * 100000, t2 * 100000))
How to slice a deque?