Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39377 > unrolled thread
| Started by | eli m <techgeek201@gmail.com> |
|---|---|
| First post | 2013-02-20 12:53 -0800 |
| Last post | 2013-02-20 16:23 -0500 |
| Articles | 4 — 4 participants |
Back to article view | Back to comp.lang.python
Import Question eli m <techgeek201@gmail.com> - 2013-02-20 12:53 -0800
Re: Import Question Matteo Boscolo <matteo.boscolo@boscolini.eu> - 2013-02-20 22:01 +0100
Re: Import Question Michael Herman <hermanmu@gmail.com> - 2013-02-20 13:03 -0800
Re: Import Question Dave Angel <davea@davea.name> - 2013-02-20 16:23 -0500
| From | eli m <techgeek201@gmail.com> |
|---|---|
| Date | 2013-02-20 12:53 -0800 |
| Subject | Import Question |
| Message-ID | <c5a35a50-320e-4c1f-a825-c80becd9d20f@googlegroups.com> |
How long does it take for the program to import something? I am asking this because i have like 7 imports at the beginning of my program and i am thinking thats the reason why it is slow to start up. Thanks in advance.
[toc] | [next] | [standalone]
| From | Matteo Boscolo <matteo.boscolo@boscolini.eu> |
|---|---|
| Date | 2013-02-20 22:01 +0100 |
| Message-ID | <mailman.2127.1361394133.2939.python-list@python.org> |
| In reply to | #39377 |
Il 20/02/2013 21:53, eli m ha scritto: > How long does it take for the program to import something? I am asking this because i have like 7 imports at the beginning of my program and i am thinking thats the reason why it is slow to start up. Thanks in advance. It depend of your code module code.. if inside your module there is some code (no def or class) this code will be executed, and if for example you have some loop or some db query this will be executed too. regards, Matteo
[toc] | [prev] | [next] | [standalone]
| From | Michael Herman <hermanmu@gmail.com> |
|---|---|
| Date | 2013-02-20 13:03 -0800 |
| Message-ID | <mailman.2128.1361394228.2939.python-list@python.org> |
| In reply to | #39377 |
[Multipart message — attachments visible in raw view] — view raw
you can check each import as it varies in loading time: time python -c "import [name of module]" example: time python -c "import flask" On Wed, Feb 20, 2013 at 12:53 PM, eli m <techgeek201@gmail.com> wrote: > How long does it take for the program to import something? I am asking > this because i have like 7 imports at the beginning of my program and i am > thinking thats the reason why it is slow to start up. Thanks in advance. > -- > http://mail.python.org/mailman/listinfo/python-list >
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-02-20 16:23 -0500 |
| Message-ID | <mailman.2129.1361395441.2939.python-list@python.org> |
| In reply to | #39377 |
On 02/20/2013 03:53 PM, eli m wrote: > How long does it take for the program to import something? I am asking this because i have like 7 imports at the beginning of my program and i am thinking thats the reason why it is slow to start up. Thanks in advance. > That would be easy to measure. If you just want a visible indication, put a print before and after those imports, and see how long between. Or use the time module to measure it. Notice that it's possible to write a module that consumes hours during import. All top level code will be executed. So if there's any substantial code there that's not conditional, it'll cost you. For the rest of the message, I'll assume you don't have any time-consuming initialization code. Since there are dozens of imports that happen before your code even begins, I doubt if your own imports make that much difference. Further, some of them are probably already imported, and it's very fast to "import" something already in the cache. About as long as a dict lookup followed by an assignment. When I look at len(list(sys.modules.iterkeys())) in Python 2.7.3, I get the value 243 Some of them are binary modules, which load pretty much instantaneously, and the others are probably precompiled, but I still expect them to swamp the 7 you're doing. BTW, if you measure it, be aware that the first time you import a module, it must be compiled, but then it saves as a .pyc file, and the next time it'll be much quicker. -- DaveA
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web