Basic question about speed/coding style/memory
jeanpierreda at gmail.com
Sun Jul 22 03:31:31 CEST 2012
On Sat, Jul 21, 2012 at 5:06 AM, Steven D'Aprano
<steve+comp.lang.python at 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 real, and
> not just measurement error, the difference is insignificant.
It's probably real. For if-else, the true case needs to make a jump
before it returns, but for if-return, there's no jump and the return
> So, don't worry about which is faster. Write whichever is more natural,
> easier to read and write.
The most important advice. Even when it's a larger difference! :)
More information about the Python-list