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


Groups > comp.lang.python > #8341

Re: performance critical Python features

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '(at': 0.03; 'example:': 0.03; '(although': 0.05; 'sure.': 0.05; 'subject:Python': 0.06; 'python': 0.08; 'calculates': 0.09; 'defined,': 0.09; 'executed': 0.09; 'subject:features': 0.09; 'am,': 0.13; 'received:209.85.214.174': 0.13; 'received:mail- iw0-f174.google.com': 0.13; 'wrote:': 0.15; 'cache.': 0.16; 'calculation': 0.16; 'frequently.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'algorithm': 0.16; 'this:': 0.16; '>>>': 0.16; 'def': 0.16; 'written': 0.17; 'repeated': 0.19; "aren't": 0.22; 'header:In-Reply-To:1': 0.22; 'assume': 0.23; 'least,': 0.23; 'once.': 0.23; 'pieces': 0.23; 'code': 0.24; 'fri,': 0.28; 'guess': 0.28; 'received:209.85.214': 0.28; 'message-id:@mail.gmail.com': 0.28; '24,': 0.29; 'example': 0.30; 'fact': 0.30; 'chris': 0.32; 'generally': 0.33; 'done': 0.33; 'does': 0.33; 'to:addr:python-list': 0.34; "can't": 0.34; "we're": 0.34; 'things': 0.35; 'operations': 0.36; 'optimization': 0.36; 'functions.': 0.37; 'received:google.com': 0.37; 'but': 0.37; 'received:209.85': 0.38; 'could': 0.38; 'eric': 0.38; 'steven': 0.38; 'think': 0.38; 'subject:: ': 0.38; 'common': 0.39; 'expensive': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.39; 'called': 0.40; 'would': 0.40; 'more': 0.60; 'your': 0.61; 'results': 0.62; 'circle': 0.67; 'jun': 0.67; 'heavy': 0.71; 'definition:': 0.84; 'different.': 0.84; 'toy': 0.84; 'snow': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=hdVmJWFvmKkYHelJs56bjmDHGgh7alVGoxCmmRJ29ac=; b=EjDHoq84kJdrBbLmCcEYtLnr+xYMB2VfyBgbdf8MkIiVclNbcKwIoNDW6+WOBBvPxa 7hr7p5Iw9sNqWSLs4WD+IH3GbxlOA+N7uIMbDzXwxPoFbmFdQReqQPRgZLbcvtRddzXQ kLYyKrZfGflqf2NTkNJbyVpQc+uZsYG5oKxO4=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=ZP/3v2R3nRCaL7BbnN0zacC4A8Y9LrdUirIQ6GGRuAwGhjA1WC8K8MjCaRB1lUHDcb WD+Xn83AJ9udQvmgXwuOWbimf1UDkUUp+Rnwp6SxPXs95T1R5hsomnyCqode1zFVvk85 7H4XYGRVO/efO+cDIVZZfEehJQjEP1KnSQLvM=
MIME-Version 1.0
In-Reply-To <4e03d54e$0$29975$c3e8da3$5496439d@news.astraweb.com>
References <BANLkTimZk6C4PECy6KNrQ91fWNQG37Mgjw@mail.gmail.com> <mailman.337.1308852020.1164.python-list@python.org> <4e03d54e$0$29975$c3e8da3$5496439d@news.astraweb.com>
Date Fri, 24 Jun 2011 12:08:30 +1000
Subject Re: performance critical Python features
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
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.347.1308881313.1164.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 82.94.164.166
X-Trace 1308881314 news.xs4all.nl 14133 [::ffff:82.94.164.166]:37172
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8341

Show key headers only | View raw


On Fri, Jun 24, 2011 at 10:07 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> On Fri, 24 Jun 2011 04:00:17 +1000, Chris Angelico wrote:
>
>> On Fri, Jun 24, 2011 at 2:58 AM, Eric Snow <ericsnowcurrently@gmail.com>
>> wrote:
>>> So, which are the other pieces of Python that really need the heavy
>>> optimization and which are those that don't?  Thanks.
>>>
>>>
>> Things that are executed once (imports, class/func definitions) and
>
> You can't assume that either of those things are executed once. Consider
> this toy example:

Sure. I was talking in generalities; of course you can do expensive
operations frequently. If you wanted to, you could do this:

radius=5
circum=0
for i in range(10,1000):
    c=radius*calculate_pi_to_n_decimals(i)
    if c>circum: circum=c

Calculates the highest possible circumference of a circle of that
radius. Does this mean we now have to optimize the pi calculation
algorithm so it can be used in a tight loop? Well, apart from the fact
that this code is moronic, no. All you need to do is cache. (Although
I guess in a way that's an optimization of the algorithm. It's the
same optimization as is done for imports.)

But generally speaking, functions are called more often than they're
defined, especially when we're talking about tight loops. And while
your example could be written without the repeated definition:

def outer(a, b):
   x=b**2 - a**2
   return (x*a - b)*(x*b - a) - 1

results = [outer(a, b) for (a, b) in coordinate_pairs()]

(at least, I think this is the same functionality), if inner() were
recursive, that would be different. But recursive inner functions
aren't nearly as common as write-once-call-many functions.

ChrisA

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


Thread

Re: performance critical Python features Chris Angelico <rosuav@gmail.com> - 2011-06-24 04:00 +1000
  Re: performance critical Python features Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-24 00:07 +0000
    Re: performance critical Python features Chris Angelico <rosuav@gmail.com> - 2011-06-24 12:08 +1000

csiph-web