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


Groups > comp.lang.python > #49980

Re: How to make this faster

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <fabiosantosart@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.009
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python.': 0.02; 'syntax': 0.04; 'argument': 0.05; 'cpython': 0.05; 'indexing': 0.07; 'arrays': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'suggest': 0.14; 'array.': 0.16; 'benjamin': 0.16; 'dictionaries': 0.16; 'looping': 0.16; 'numpy': 0.16; 'subject:make': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'numerical': 0.19; 'solution.': 0.20; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '&gt;': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'array': 0.29; "doesn't": 0.30; 'nature': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'getting': 0.31; '+0100,': 0.31; 'ordinary': 0.31; 'class': 0.32; 'lists': 0.32; 'stuff': 0.32; 'run': 0.32; 'fri,': 0.33; 'comment': 0.34; 'sense': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'version': 0.36; 'really': 0.36; 'thanks': 0.36; 'seconds': 0.37; 'e.g.': 0.38; 'lists.': 0.38; 'fact': 0.38; 'expect': 0.39; 'even': 0.60; 'most': 0.60; 'range': 0.61; "you're": 0.61; 'making': 0.63; 'kind': 0.63; 'real': 0.63; 'skip:n 10': 0.64; 'more': 0.64; 'citizens': 0.65; 'jul': 0.74; 'subject:this': 0.83; 'faster.': 0.84; 'improvement,': 0.84; 'oscar': 0.84; 'choice.': 0.93; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=2BEzVvREvJ5tiLg+t28WlZnW5aOxMVrbpMqnWwG1f/w=; b=EcbE5YPHEy7LR98jAn9ImGeDp4VKuwYjG/HDfE0ZWUz2sEkeV7Ra8BYr+e+h75VTUS YZ/q+SubZthRoFq7OW1q11V34rD97fAqw62kntrCqueviVni4XO8YZL3JdSP0PYhht5u ydLv+iatICU5qu6YF2oUatcWTJa50sogA3BTtFxHdJ08+ZwqqLKhj5bYI/sy/XIjBfM+ y3S63Us2eUYIJ9f3Ln2bcN3Lsw6dKlqH6MGHycKTfy4Vgzy2a5QxSKuaUPMYJoe2AsCg MfzabWrrufY5de20NoiqJFu1MzePrBGXid39gHQlz4/SJEfmhlDW2ma33QbE8Zw1XQIy 8YsA==
MIME-Version 1.0
X-Received by 10.224.123.68 with SMTP id o4mr8860151qar.106.1373028298068; Fri, 05 Jul 2013 05:44:58 -0700 (PDT)
In-Reply-To <b3nmtfFojnkU3@mid.dfncis.de>
References <b3ne2rFojnkU1@mid.dfncis.de> <b3nmtfFojnkU3@mid.dfncis.de>
Date Fri, 5 Jul 2013 13:44:57 +0100
Subject Re: How to make this faster
From Fábio Santos <fabiosantosart@gmail.com>
To Helmut Jarausch <jarausch@igpm.rwth-aachen.de>
Content-Type multipart/alternative; boundary=047d7bd6bc92f91faf04e0c30fda
Cc python-list@python.org
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 <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.4294.1373028307.3114.python-list@python.org> (permalink)
Lines 71
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1373028307 news.xs4all.nl 15929 [2001:888:2000:d::a6]:36469
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:49980

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 5 Jul 2013 11:58, "Helmut Jarausch" <jarausch@igpm.rwth-aachen.de> wrote:
>
> On Fri, 05 Jul 2013 11:13:33 +0100, Oscar Benjamin wrote:
>
> > My one comment is that you're not really making the most out of numpy
> > arrays. Numpy's ndarrays are efficient when each line of Python code
> > is triggering a large number of numerical computations performed over
> > the array. Because of their N-dimensional nature and the fact that
> > they are in some sense second class citizens in CPython they are often
> > not as good as lists for this kind of looping and indexing.
> >
> > I would actually expect this program to run faster with ordinary
> > Python lists and lists of lists. It means that you need to change e.g.
> > Grid[r, c] to Grid[r][c] but really I think that the indexing syntax
> > is all you're getting out of numpy here.
> >
>
> Thanks Oscar, that was a big improvement, indeed.
> Using lists of lists instead of numpy arrays made the code more than
> twice as fast (13 seconds down to 6 seconds)
>
> Since I don't do any numerical stuff with the arrays, Numpy doesn't seem
to be
> a good choice. I think this is an argument to add real arrays to Python.
>
> I even tried to use dictionaries instead of Numpy arrays. This version is
a bit
> slower then the lists of lists version (7.2 seconds instead of 6 second)
but still
> much faster than the Numpy array solution.

May I suggest you avoid range and use enumerate(the_array) instead? It
might be faster.

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


Thread

How to make this faster Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-07-05 08:22 +0000
  Re: How to make this faster Fábio Santos <fabiosantosart@gmail.com> - 2013-07-05 10:38 +0100
  Re: How to make this faster Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-07-05 10:07 +0000
  Re: How to make this faster Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-07-05 11:13 +0100
  Re: How to make this faster Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-07-05 10:53 +0000
    Re: How to make this faster Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-05 12:02 +0000
    Re: How to make this faster Fábio Santos <fabiosantosart@gmail.com> - 2013-07-05 13:44 +0100
    Re: How to make this faster Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-07-05 14:41 +0100
    Re: How to make this faster Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-07-05 14:28 +0000
      Re: How to make this faster Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-07-05 15:45 +0100
    Re: How to make this faster Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-07-05 14:48 +0000
      Re: How to make this faster Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-07-05 16:26 +0100
    Re: How to make this faster Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-07-05 14:54 +0000
      Re: How to make this faster Fábio Santos <fabiosantosart@gmail.com> - 2013-07-05 16:18 +0100
      Re: How to make this faster Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-05 16:24 +0000
    Re: How to make this faster Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-07-05 15:17 +0000
      Re: How to make this faster Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-07-05 16:38 +0100
      Re: How to make this faster MRAB <python@mrabarnett.plus.com> - 2013-07-05 17:25 +0100
      Re: How to make this faster Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-06 02:45 +0100
    Re: How to make this faster Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-07-05 15:47 +0000
      Re: How to make this faster Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-05 16:52 +0000
    Re: How to make this faster Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-07-05 16:07 +0000
      Re: How to make this faster Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-05 16:50 +0000
        Re: How to make this faster Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-07-05 18:39 +0000
          Re: How to make this faster Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-06 03:05 +0000
          Re: How to make this faster Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-07-06 07:25 +0000
    Re: How to make this faster Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2013-07-05 18:42 +0000

csiph-web