diff options
author | Christian Heimes <christian@cheimes.de> | 2008-02-28 12:27:11 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-02-28 12:27:11 (GMT) |
commit | 9e7f1d2e965400edcb2c0cb7fee625ef2b595eb5 (patch) | |
tree | a568514bdd94fa8fcaa2ea8ae488c7200e6c33db /Doc/library/itertools.rst | |
parent | 380f7f22fa82089ac35eb84ec5feac9aa3f2efed (diff) | |
download | cpython-9e7f1d2e965400edcb2c0cb7fee625ef2b595eb5.zip cpython-9e7f1d2e965400edcb2c0cb7fee625ef2b595eb5.tar.gz cpython-9e7f1d2e965400edcb2c0cb7fee625ef2b595eb5.tar.bz2 |
Merged revisions 61038,61042-61045,61047,61050,61053,61055-61056,61061-61062,61066,61068,61070,61083,61085,61092-61103 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61098 | jeffrey.yasskin | 2008-02-28 05:45:36 +0100 (Thu, 28 Feb 2008) | 7 lines
Move abc._Abstract into object by adding a new flag Py_TPFLAGS_IS_ABSTRACT,
which forbids constructing types that have it set. The effect is to speed
./python.exe -m timeit -s 'import abc' -s 'class Foo(object): __metaclass__ = abc.ABCMeta' 'Foo()'
up from 2.5us to 0.201us. This fixes issue 1762.
........
r61099 | jeffrey.yasskin | 2008-02-28 06:53:18 +0100 (Thu, 28 Feb 2008) | 3 lines
Speed test_socketserver up from 28.739s to 0.226s, simplify the logic, and make
sure all tests run even if some fail.
........
r61100 | jeffrey.yasskin | 2008-02-28 07:09:19 +0100 (Thu, 28 Feb 2008) | 21 lines
Thread.start() used sleep(0.000001) to make sure it didn't return before the
new thread had started. At least on my MacBook Pro, that wound up sleeping for
a full 10ms (probably 1 jiffy). By using an Event instead, we can be absolutely
certain that the thread has started, and return more quickly (217us).
Before:
$ ./python.exe -m timeit -s 'from threading import Thread' 't = Thread(); t.start(); t.join()'
100 loops, best of 3: 10.3 msec per loop
$ ./python.exe -m timeit -s 'from threading import Thread; t = Thread()' 't.isAlive()'
1000000 loops, best of 3: 0.47 usec per loop
After:
$ ./python.exe -m timeit -s 'from threading import Thread' 't = Thread(); t.start(); t.join()'
1000 loops, best of 3: 217 usec per loop
$ ./python.exe -m timeit -s 'from threading import Thread; t = Thread()' 't.isAlive()'
1000000 loops, best of 3: 0.86 usec per loop
To be fair, the 10ms isn't CPU time, and other threads including the spawned
one get to run during it. There are also some slightly more complicated ways to
get back the .4us in isAlive() if we want.
........
r61101 | raymond.hettinger | 2008-02-28 10:23:48 +0100 (Thu, 28 Feb 2008) | 1 line
Add repeat keyword argument to itertools.product().
........
r61102 | christian.heimes | 2008-02-28 12:18:49 +0100 (Thu, 28 Feb 2008) | 1 line
The empty tuple is usually a singleton with a much higher refcnt than 1
........
Diffstat (limited to 'Doc/library/itertools.rst')
-rw-r--r-- | Doc/library/itertools.rst | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Doc/library/itertools.rst b/Doc/library/itertools.rst index 826fa45..73abb89 100644 --- a/Doc/library/itertools.rst +++ b/Doc/library/itertools.rst @@ -327,7 +327,7 @@ loops that truncate the stream. example :func:`islice` or :func:`takewhile`). -.. function:: product(*iterables) +.. function:: product(*iterables[, repeat]) Cartesian product of input iterables. @@ -340,11 +340,15 @@ loops that truncate the stream. so that if the inputs iterables are sorted, the product tuples are emitted in sorted order. + To compute the product of an iterable with itself, specify the number of + repetitions with the optional *repeat* keyword argument. For example, + ``product(A, repeat=4)`` means the same as ``product(A, A, A, A)``. + Equivalent to the following except that the actual implementation does not build-up intermediate results in memory:: - def product(*args): - pools = map(tuple, args) + def product(*args, **kwds): + pools = map(tuple, args) * kwds.get('repeat', 1) if pools: result = [[]] for pool in pools: |