This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jameinel
Recipients belopolsky, jameinel, rhettinger
Date 2008-04-24.18:23:46
SpamBayes Score 0.00047415198
Marked as misclassified No
Message-id <4810D028.5040702@arbash-meinel.com>
In-reply-to <1208981995.67.0.765672635502.issue2672@psf.upfronthosting.co.za>
Content
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexander Belopolsky wrote:
> Alexander Belopolsky <belopolsky@users.sourceforge.net> 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(10000)); y = []' 'x.update(y)'
> 1000000 loops, best of 3: 0.38 usec per loop
> $ python -m timeit -s 'x = set(range(10000)); y = (i for i in [])'
> 'x.update(y)'
> 1000000 loops, best of 3: 0.335 usec per loop
> 
> ----------
> nosy: +belopolsky
> 
> __________________________________
> Tracker <report@bugs.python.org>
> <http://bugs.python.org/issue2672>
> __________________________________
> 

That is true, though if I just force a generator overhead:

% python -m timeit -s 'x = set(range(10000)); y = []' 'x.update(y)'
1000000 loops, best of 3: 0.204 usec per loop
% python -m timeit -s 'x = set(range(10000)); y = (i for i in [])'
'x.update(y)'
10000000 loops, best of 3: 0.173 usec per loop
% python -m timeit -s 'x = set(range(10000)); l = []' 'x.update(i for i
in l)'
1000000 loops, best of 3: 0.662 usec per loop
 python -m timeit -s 'x = set(range(10000)); l = []; y = (i for i in l)'
'(i for i in l); x.update(y)'
1000000 loops, best of 3: 1.87 usec per loop

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 why does: "(i for i in l); x.update(y)" take an additional 1.208 usec.

(I'm certainly willing to believe that set.update() is generator/list
agnostic, but something weird is still happening.)

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIENAoJdeBCYSNAAMRAk2yAJ4okAalR6zWD0/E5XHei/ckce+L7QCgstEQ
l+6+bl7oAJMhdJ70viqicnQ=
=pLX6
-----END PGP SIGNATURE-----
History
Date User Action Args
2008-04-24 18:23:48jameinelsetspambayes_score: 0.000474152 -> 0.00047415198
recipients: + jameinel, rhettinger, belopolsky
2008-04-24 18:23:47jameinellinkissue2672 messages
2008-04-24 18:23:46jameinelcreate