Skip to content

Instantly share code, notes, and snippets.

@smarnach
Created February 21, 2012 17:37
Show Gist options
  • Save smarnach/1877613 to your computer and use it in GitHub Desktop.
Save smarnach/1877613 to your computer and use it in GitHub Desktop.
In [3]: consume = collections.deque(maxlen=0).extend
In [4]: def f(a):
...: consume(x for x in a)
...:
In [5]: def g(a):
...: consume(a)
...:
In [6]: def h(a):
...: for x in a:
...: x
...:
In [7]: a = range(100000)
In [8]: %timeit f(a)
100 loops, best of 3: 5.52 ms per loop
In [9]: %timeit g(a)
1000 loops, best of 3: 703 us per loop
In [10]: %timeit h(a)
100 loops, best of 3: 2.32 ms per loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment