- Python Home
- About
- News
- Documentation
- Downloads
- Community
- Foundation
- Developer's Guide
- Issue Tracker
- Issues
- Summaries
- User
- Administration
- Help
➜
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 | belopolsky |
|---|---|
| Recipients | belopolsky, jameinel, rhettinger |
| Date | 2008-04-24.19:29:33 |
| SpamBayes Score | 0.015214344 |
| Marked as misclassified | No |
| Message-id | <d38f5330804241229p796acbc4x7280c37a644b2e30@mail.gmail.com> |
| In-reply-to | <4810D028.5040702@arbash-meinel.com> |
| Content |
|---|
On Thu, Apr 24, 2008 at 2:23 PM, John Arbash Meinel <report@bugs.python.org> 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 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.) I've seen a similar strangeness in timings: $ python -m timeit '(i for i in [])' 100000 loops, best of 3: 4.16 usec per loop but $ python -m timeit -s 'x = set()' 'x.update(i for i in [])' 1000000 loops, best of 3: 1.31 usec per loop on the other hand, $ python -m timeit -s 'x = []' 'x.extend(i for i in [])' 100000 loops, best of 3: 4.54 usec per loop How can x.update(i for i in []) take *less* time than simply creating a genexp? Note that there is no apparent bytecode tricks here: 1 0 LOAD_CONST 0 (<code object <genexpr> at 0xf7e88920, file "<stdin>", line 1>) 3 MAKE_FUNCTION 0 6 BUILD_LIST 0 9 GET_ITER 10 CALL_FUNCTION 1 13 RETURN_VALUE >>> dis(lambda:x.update(i for i in [])) 1 0 LOAD_GLOBAL 0 (x) 3 LOAD_ATTR 1 (update) 6 LOAD_CONST 0 (<code object <genexpr> at 0xf7e88920, file "<stdin>", line 1>) 9 MAKE_FUNCTION 0 12 BUILD_LIST 0 15 GET_ITER 16 CALL_FUNCTION 1 19 CALL_FUNCTION 1 22 RETURN_VALUE |
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2008-04-24 19:29:35 | belopolsky | set | spambayes_score: 0.0152143 -> 0.015214344 recipients: + belopolsky, rhettinger, jameinel |
| 2008-04-24 19:29:34 | belopolsky | link | issue2672 messages |
| 2008-04-24 19:29:33 | belopolsky | create |
Powered by Roundup Copyright © 1990-2022, Python Software Foundation
Legal Statements
