Re: Basic question about speed/coding style/memory

2012-07-23 Thread 88888 Dihedral
Jan Riechers於 2012年7月21日星期六UTC+8下午3時33分27秒寫道: Hello Pythonlist, I have one very basic question about speed,memory friendly coding, and coding style of the following easy quot;ifquot;-statement in Python 2.7, but Im sure its also the same in Python 3.x Block

Re: Basic question about speed/coding style/memory

2012-07-23 Thread 88888 Dihedral
Chris Angelico於 2012年7月21日星期六UTC+8下午5時04分12秒寫道: On Sat, Jul 21, 2012 at 5:33 PM, Jan Riechers lt;janpet...@freenet.degt; wrote: gt; Block gt; #-- gt; if statemente_true: gt; doSomething() gt; else: gt; doSomethingElseInstead() gt; gt;

Basic question about speed/coding style/memory

2012-07-21 Thread Jan Riechers
Hello Pythonlist, I have one very basic question about speed,memory friendly coding, and coding style of the following easy if-statement in Python 2.7, but Im sure its also the same in Python 3.x Block #-- if statemente_true: doSomething() else:

Re: Basic question about speed/coding style/memory

2012-07-21 Thread Andrew Berg
On 7/21/2012 2:33 AM, Jan Riechers wrote: Block ... versus this block: ... Now, very briefly, what is the better way to proceed in terms of execution speed, readability, coding style? Using if/else is the most readable in the general sense. Using return (or break or continue as applicable)

Re: Basic question about speed/coding style/memory

2012-07-21 Thread Jan Riechers
On 21.07.2012 11:02, Andrew Berg wrote: On 7/21/2012 2:33 AM, Jan Riechers wrote: Block ... versus this block: ... Now, very briefly, what is the better way to proceed in terms of execution speed, readability, coding style? Using if/else is the most readable in the general sense. Using return

Re: Basic question about speed/coding style/memory

2012-07-21 Thread Chris Angelico
On Sat, Jul 21, 2012 at 5:33 PM, Jan Riechers janpet...@freenet.de wrote: Block #-- if statemente_true: doSomething() else: doSomethingElseInstead() #-- This means, to me, that the two options are peers - you

Re: Basic question about speed/coding style/memory

2012-07-21 Thread Andrew Berg
On 7/21/2012 3:13 AM, Jan Riechers wrote: Cause, as I understand the interpreter chooses either the else (1st block) or just proceeds with following code outside the if. If none of the if/elif statements evaluate to something true, the else block is executed. So if there is some overhead in

Re: Basic question about speed/coding style/memory

2012-07-21 Thread Steven D'Aprano
On Sat, 21 Jul 2012 10:33:27 +0300, Jan Riechers wrote: Hello Pythonlist, I have one very basic question about speed,memory friendly coding, and coding style of the following easy if-statement in Python 2.7, but Im sure its also the same in Python 3.x I assume that the following is meant

Re: Basic question about speed/coding style/memory

2012-07-21 Thread Jan Riechers
On 21.07.2012 12:06, Steven D'Aprano wrote: But in general, you're worrying too much about trivia. One way or the other, any speed difference will be trivial. Write whatever style reads and writes most naturally, and only worry about what's faster where it actually counts. Notice that I

Re: Basic question about speed/coding style/memory

2012-07-21 Thread Thomas 'PointedEars' Lahn
Jan Riechers wrote: I have one very basic question about speed,memory friendly coding, and coding style of the following easy if-statement in Python 2.7, but Im sure its also the same in Python 3.x Block #-- if statemente_true: doSomething() else:

Re: Basic question about speed/coding style/memory

2012-07-21 Thread Devin Jeanpierre
On Sat, Jul 21, 2012 at 5:06 AM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: So there is approximately 0.03 second difference per TWO MILLION if...else blocks, or about 15 nanoseconds each. This is highly unlikely to be the bottleneck in your code. Assuming the difference is