[Tutor] Efficiency of while versus (x)range

Andre Engels andreengels at gmail.com
Thu Mar 17 09:18:25 CET 2011


On Thu, Mar 17, 2011 at 8:45 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:

> Note that a web application involves many things outside of your own code
> that seriously impact the performance and/or resource requirements. Database
> access can be slow, excessively dynamic page generation and template engines
> can become a bottleneck, badly configured caching can eat your RAM and slow
> down your response times.

Yes, that has been my experience too back when I did web applications
in Python. I had several cases where the page took too long to load;
in all but one cases the issue was resolved by getting a database
access out of a loop, thus changing many database accesses into one.
The remaining case was also resolved in the area of database access,
this time by checking whether a particular database result was one
that we needed in the database request instead of afterward in Python.

> You shouldn't be. Optimising at that level is clearly the wrong place to
> start with.

The three rules of optimisation in Python:
1. Only optimise if your system is actually too slow
2. Only optimise the thing that is actually causing the slowness
3. If you are of the opinion that should break one of these rules, you
are using the wrong language.

> Optimisation is
> something that you should start to apply when your test suite is large
> enough to catch the bugs you introduce by doing it.

That's a quote to remember :-)


-- 
André Engels, andreengels at gmail.com


More information about the Tutor mailing list