John Arbash Meinel [EMAIL PROTECTED] added the comment:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Alexander Belopolsky wrote:
Alexander Belopolsky [EMAIL PROTECTED] added the comment:
This has nothing to do with set.update, the difference is due to the
time to setup the generator:
$
Alexander Belopolsky [EMAIL PROTECTED] added the comment:
On Thu, Apr 24, 2008 at 2:23 PM, John Arbash Meinel
[EMAIL PROTECTED] wrote:
..
So if you compare consuming a generator multiple times to creating it
each time, it is 0.662 usec - 0.173 usec = 0.489 usec to create a generator.
So
Raymond Hettinger [EMAIL PROTECTED] added the comment:
John, when y=[], the update method has to create a new list iterator on
each invocation. But when y is a genexp, it is self-iterable (iow, iter
(y) will return self, not a new object).
Also, when doing timings, it can be helpful to
John Arbash Meinel [EMAIL PROTECTED] added the comment:
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Raymond Hettinger wrote:
Raymond Hettinger [EMAIL PROTECTED] added the comment:
John, when y=[], the update method has to create a new list iterator on
each invocation. But when y is a
Alexander Belopolsky [EMAIL PROTECTED] added the comment:
This has nothing to do with set.update, the difference is due to the
time to setup the generator:
$ python -m timeit -s 'x = set(range(1)); y = []' 'x.update(y)'
100 loops, best of 3: 0.38 usec per loop
$ python -m timeit -s 'x =
Raymond Hettinger [EMAIL PROTECTED] added the comment:
I concur. The source code for set_update() in Objects/setobject.c
shows that both versions are accessed through the iterator protocol, so
what you're seeing are the basic performance differences (start-up and
per-item costs) for genexps
New submission from John Arbash Meinel [EMAIL PROTECTED]:
I was performance profiling some of my own code, and I ran into
something unexpected. Specifically,
set.update(empty_generator_expression) was significantly slower than
set.update(empty_list_expression).
I double checked my findings with
Changes by John Arbash Meinel [EMAIL PROTECTED]:
--
type: - performance
__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2672
__
___
Python-bugs-list mailing list
Changes by Raymond Hettinger [EMAIL PROTECTED]:
--
assignee: - rhettinger
nosy: +rhettinger
__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2672
__
___
Python-bugs-list