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 jameinel
Date 2008-04-23.02:44:41
SpamBayes Score 0.35771817
Marked as misclassified No
Message-id <1208918684.07.0.896118455388.issue2672@psf.upfronthosting.co.za>
In-reply-to
Content
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 timeit:

With python 2.4.3:

$ python -m timeit -s 'x = set(range(10000))' 'x.update([])'
1000000 loops, best of 3: 0.296 usec per loop
$ python -m timeit -s 'x = set(range(10000))' 'x.update(y for y in [])'
1000000 loops, best of 3: 0.837 usec per loop
$ python -m timeit -s 'x = set(range(10000))' 'x.update([y for y in []])'
1000000 loops, best of 3: 0.462 usec per loop

With 2.5.1 (on a different machine)
$ python -m timeit -s 'x = set(range(10000))' 'x.update([])'
1000000 loops, best of 3: 0.265 usec per loop
$ python -m timeit -s 'x = set(range(10000))' 'x.update(y for y in [])'
1000000 loops, best of 3: 0.717 usec per loop
$ python -m timeit -s 'x = set(range(10000))' 'x.update([y for y in []])'
1000000 loops, best of 3: 0.39 usec per loop

So generally, it is about 2x faster to create the empty list expression
and pass it in than to use an empty generator.
History
Date User Action Args
2008-04-23 02:44:44jameinelsetspambayes_score: 0.357718 -> 0.35771817
recipients: + jameinel
2008-04-23 02:44:44jameinelsetspambayes_score: 0.357718 -> 0.357718
messageid: <1208918684.07.0.896118455388.issue2672@psf.upfronthosting.co.za>
2008-04-23 02:44:42jameinellinkissue2672 messages
2008-04-23 02:44:41jameinelcreate