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


Groups > comp.lang.python > #61130

Re: squeeze out some performance

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'arrays': 0.09; 'pixels': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; '(assuming': 0.16; 'coordinates': 0.16; 'end).': 0.16; 'geometry,': 0.16; 'numpy': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'spots': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'import': 0.22; 'header:User-Agent:1': 0.23; 'module,': 0.24; 'replace': 0.24; 'sort': 0.25; 'extension': 0.26; 'header:X-Complaints-To:1': 0.27; 'idea': 0.28; 'array': 0.29; 'robert': 0.30; 'sets': 0.30; 'skip:( 20': 0.30; 'code': 0.31; 'are.': 0.31; 'operations.': 0.31; 'subject:some': 0.31; 'values.': 0.31; 'probably': 0.32; 'another': 0.32; 'maybe': 0.34; 'could': 0.34; 'problem': 0.35; 'something': 0.35; 'possible': 0.36; 'performance': 0.37; 'e.g.': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'analyze': 0.60; 'circle': 0.68; 'hints': 0.68; 'optimized': 0.68; 'below.': 0.71; 'received:130': 0.73; 'heavy': 0.81; 'from:addr:jeremy': 0.84; 'impact.': 0.84; 'more?': 0.84; 'hot': 0.96
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Jeremy Sanders <jeremy@jeremysanders.net>
Subject Re: squeeze out some performance
Date Fri, 06 Dec 2013 10:46:46 +0100
References <ce6477c1-29c0-43b3-9e56-336a5825869b@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Gmane-NNTP-Posting-Host lap75107.mpe.mpg.de
User-Agent KNode/4.11.2
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3633.1386323183.18130.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386323183 news.xs4all.nl 2968 [2001:888:2000:d::a6]:45682
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:61130

Show key headers only | View raw


Robert Voigtländer wrote:

> I try to squeeze out some performance of the code pasted on the link
> below. http://pastebin.com/gMnqprST
> 
> The code will be used to continuously analyze sonar sensor data. I set
> this up to calculate all coordinates in a sonar cone without heavy use of
> trigonometry (assuming that this way is faster in the end).
> 
> I optimized as much as I could. Maybe one of you has another bright idea
> to squeeze out a bit more?

This sort of code is probably harder to make faster in pure python. You 
could try profiling it to see where the hot spots are. Perhaps the choice of 
arrays or sets might have some speed impact.

One idea would be to use something like cython to compile your python code 
to an extension module, with some hints to the types of the various values.

I would go down the geometry route. If you can restate your problem in terms 
of geometry, it might be possible to replace all that code with a few numpy 
array operations.

e.g. for finding pixels in a circle of radius 50
import numpy as np
radiussqd = np.fromfunction(lambda y,x: (y-50)**2+(x-50)**2, (100,100) )
all_y, all_x = np.indices((100,100))
yvals = all_y[radiussqd < 50**2]

Jeremy

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


Thread

squeeze out some performance Robert Voigtländer <r.voigtlaender@gmail.com> - 2013-12-06 00:47 -0800
  Re: squeeze out some performance Jeremy Sanders <jeremy@jeremysanders.net> - 2013-12-06 10:46 +0100
  Re: squeeze out some performance Chris Angelico <rosuav@gmail.com> - 2013-12-06 23:13 +1100
    Re: squeeze out some performance Robert Voigtländer <r.voigtlaender@gmail.com> - 2013-12-06 08:29 -0800
      Re: squeeze out some performance Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-06 16:36 +0000
        Re: squeeze out some performance Robert Voigtländer <r.voigtlaender@gmail.com> - 2013-12-06 08:44 -0800
  Re: squeeze out some performance John Ladasky <john_ladasky@sbcglobal.net> - 2013-12-06 08:52 -0800
    Re: squeeze out some performance Joel Goldstick <joel.goldstick@gmail.com> - 2013-12-06 17:07 -0500
    Re: squeeze out some performance Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-06 22:38 +0000
    Re: squeeze out some performance Dan Stromberg <drsalists@gmail.com> - 2013-12-06 15:01 -0800
      Re: squeeze out some performance Robert Voigtländer <r.voigtlaender@gmail.com> - 2013-12-09 06:19 -0800
        Re: squeeze out some performance Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-09 14:52 +0000
    Re: squeeze out some performance Robin Becker <robin@reportlab.com> - 2013-12-09 15:54 +0000
    Re: squeeze out some performance Dave Angel <davea@davea.name> - 2013-12-09 15:46 -0500
    Re: squeeze out some performance Robin Becker <robin@reportlab.com> - 2013-12-10 12:54 +0000
  Re: squeeze out some performance Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-09 23:57 +0000
    Re: squeeze out some performance Robert Voigtländer <r.voigtlaender@gmail.com> - 2013-12-10 04:14 -0800

csiph-web