Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #25786

Re: Basic question about speed/coding style/memory

Path csiph.com!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <jeanpierreda@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '21,': 0.07; 'subject:question': 0.08; 'advice.': 0.09; 'returns,': 0.09; 'whichever': 0.09; 'cc:addr:python-list': 0.10; 'sat,': 0.15; '0.03': 0.16; 'measurement': 0.16; 'real.': 0.16; 'subject:coding': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'write.': 0.16; 'wrote:': 0.17; 'code.': 0.20; 'assuming': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'subject:/': 0.28; "d'aprano": 0.29; 'steven': 0.29; 'unlikely': 0.29; 'probably': 0.29; 'received:209.85.160.46': 0.32; 'received:google.com': 0.34; 'so,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'header:Received:5': 0.40; 'your': 0.60; 'most': 0.61; 'more': 0.63; 'jul': 0.65; 'million': 0.72; 'difference!': 0.84; 'subject:Basic': 0.84; 'faster.': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=PE8OUPqBhgdwp3/yLf2cX3x9s+9wljCKLiyIAODJqJc=; b=juYMN5gIMtXxoZhEf4Rd+VZ4hdXxenKlJ63lVra6gke/fdn7ZUDIB4B9kQGg/VMhj6 kJwdUJq4sNKT717lC6exjzrXBOuD4ynOTUlHSrS8Gxzw07Rcns+LAvlRfyytXrFq4cZ1 XCymYPuId1toPWaNTKlin8cWG+LI01FYEagnCGj+qb/Bh2sh8OpncKc5VXgohCWJSmLw sB/LNBM6eNCXepKNmvamd3Gjl+QPg7ims0oMXftK9bhdh/0CAcbi8h8Mxpk6ncFOOBaI qpmqwik4K7eLUGR+BPqdcfNBFVH0b91s4Yy0sai6iMBxk1BnONDEvV8vXrUWwViH0spF 19xA==
MIME-Version 1.0
In-Reply-To <500a711f$0$29978$c3e8da3$5496439d@news.astraweb.com>
References <mailman.2364.1342856185.4697.python-list@python.org> <500a711f$0$29978$c3e8da3$5496439d@news.astraweb.com>
From Devin Jeanpierre <jeanpierreda@gmail.com>
Date Sat, 21 Jul 2012 21:31:31 -0400
Subject Re: Basic question about speed/coding style/memory
To "Steven D'Aprano" <steve+comp.lang.python@pearwood.info>
Content-Type text/plain; charset=UTF-8
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2410.1342920734.4697.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1342920734 news.xs4all.nl 6920 [2001:888:2000:d::a6]:32781
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25786

Show key headers only | View raw


On Sat, Jul 21, 2012 at 5:06 AM, Steven D'Aprano
<steve+comp.lang.python@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
is inlined.

-- Devin

> 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! :)

-- Devin

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Basic question about speed/coding style/memory Jan Riechers <janpeterr@freenet.de> - 2012-07-21 10:33 +0300
  Re: Basic question about speed/coding style/memory Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-21 09:06 +0000
    Re: Basic question about speed/coding style/memory Jan Riechers <janpeterr@freenet.de> - 2012-07-21 12:32 +0300
    Re: Basic question about speed/coding style/memory Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-07-21 21:31 -0400
  Re: Basic question about speed/coding style/memory Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-07-21 21:19 +0200
  Re: Basic question about speed/coding style/memory 88888 Dihedral <dihedral88888@googlemail.com> - 2012-07-23 14:42 -0700
  Re: Basic question about speed/coding style/memory 88888 Dihedral <dihedral88888@googlemail.com> - 2012-07-23 14:42 -0700

csiph-web