[issue2672] speed of set.update(
John Arbash Meinel
report at bugs.python.org
Thu Apr 24 23:39:39 CEST 2008
John Arbash Meinel <john at arbash-meinel.com> added the comment:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Raymond Hettinger wrote:
> Raymond Hettinger <rhettinger at users.sourceforge.net> 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 factor-out the attribute
> lookup:
>
> python -m timeit -s 'x=set(range(10000)); y=[]; xu=x.update' 'xu(y)'
>
> __________________________________
> Tracker <report at bugs.python.org>
> <http://bugs.python.org/issue2672>
> __________________________________
>
Sure, I wasn't surprised at the "set.update(y)" versus "set.update([])"
What I was surprised at is the time for:
"(i for i in [])" being about 4x longer than
"set.update(i for i in [])"
Anyway, the original issue is probably closed, whether we want to track
into the generator stuff or not is probably a different issue.
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFIEP4EJdeBCYSNAAMRAq+MAKC6tLjEtIBX7YgLNoYEfqjRKB4DzACglXjh
cEVLEP5Hu3vpeVgVYdTbAVc=
=94ja
-----END PGP SIGNATURE-----
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2672>
__________________________________
More information about the Python-bugs-list
mailing list