Created
February 21, 2012 17:37
-
-
Save smarnach/1877613 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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