Created
August 12, 2012 14:00
-
-
Save djfroofy/3331980 to your computer and use it in GitHub Desktop.
Tupling a generator vs. list comping
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
pypy-1.9 Python 2.7.2 | |
In [1]: g = xrange(10000) | |
In [2]: %timeit tuple(i for i in g) | |
1000 loops, best of 3: 659 us per loop | |
In [3]: %timeit [i for i in g] | |
10000 loops, best of 3: 77.9 us per loop | |
In [4]: g = xrange(1000000) | |
In [5]: %timeit tuple(i for i in g) | |
1 loops, best of 3: 211 ms per loop | |
In [6]: %timeit [i for i in g] | |
10 loops, best of 3: 22.8 ms per loop |
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
CPython Python 2.6.6 | |
In [13]: g = xrange(1000) | |
In [14]: %timeit tuple(i for i in g) | |
10000 loops, best of 3: 79.9 us per loop | |
In [15]: %timeit [i for i in g] | |
10000 loops, best of 3: 60.2 us per loop | |
In [16]: g = xrange(10000) | |
In [17]: %timeit tuple(i for i in g) | |
1000 loops, best of 3: 782 us per loop | |
In [18]: %timeit [i for i in g] | |
1000 loops, best of 3: 589 us per loop | |
In [19]: g = xrange(1000000) | |
In [20]: %timeit tuple(i for i in g) | |
10 loops, best of 3: 93.4 ms per loop | |
In [21]: %timeit [i for i in g] | |
10 loops, best of 3: 78.1 ms per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is for stock Python 2.6.