Re: [Tutor] Efficiency of while versus (x)range

2011-03-17 Thread Steven D'Aprano
Shane O'Connor wrote: Hi, First-time poster here. I've a question about loop efficiency - I was wondering whether this code: i = 0 while i < 1000: do something i+=1 is more efficient than: for i in range(1000): do something or: for i in xrange(1000): do something You can

Re: [Tutor] Efficiency of while versus (x)range

2011-03-17 Thread Andre Engels
On Thu, Mar 17, 2011 at 8:45 AM, Stefan Behnel 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 bec

Re: [Tutor] Efficiency of while versus (x)range

2011-03-17 Thread Stefan Behnel
Shane O'Connor, 17.03.2011 01:32: In particular, I'm using Python 2.4.3 on a web server which needs to run as fast as possible using as little memory as possible (no surprises there!). Note that a web application involves many things outside of your own code that seriously impact the performan

Re: [Tutor] Efficiency of while versus (x)range

2011-03-16 Thread Alan Gauld
"Shane O'Connor" wrote First-time poster here. I've a question about loop efficiency - I was wondering whether this code: i = 0 while i < 1000: do something i+=1 is more efficient than: for i in range(1000): do something It is impossible to tell and 99% of the time irrelevant si

Re: [Tutor] Efficiency of while versus (x)range

2011-03-16 Thread Corey Richardson
On 03/16/2011 08:32 PM, Shane O'Connor wrote: > Hi, > > First-time poster here. I've a question about loop efficiency - I was > wondering whether this code: > > i = 0 > while i < 1000: > do something > i+=1 > > is more efficient than: > > for i in range(1000): > do something > > or

Re: [Tutor] Efficiency of while versus (x)range

2011-03-16 Thread Wayne Werner
On Wed, Mar 16, 2011 at 7:32 PM, Shane O'Connor wrote: > Hi, > > First-time poster here. I've a question about loop efficiency - I was > wondering whether this code: > > i = 0 > while i < 1000: > do something > i+=1 > > is more efficient than: > > for i in range(1000): > do something >

[Tutor] Efficiency of while versus (x)range

2011-03-16 Thread Shane O'Connor
Hi, First-time poster here. I've a question about loop efficiency - I was wondering whether this code: i = 0 while i < 1000: do something i+=1 is more efficient than: for i in range(1000): do something or: for i in xrange(1000): do something In my mind, the while loop should