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


Groups > comp.lang.python > #82267

Re: Nested loops is strangely slow, totally at a loss.

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!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'element': 0.07; 'method.': 0.07; 'odd': 0.07; '*is*': 0.09; 'slow.': 0.09; 'element.': 0.16; 'exist.': 0.16; 'iterable': 0.16; 'iterables': 0.16; 'iterating': 0.16; 'returned,': 0.16; 'subject:slow': 0.16; 'tuples,': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'email addr:gmail.com&gt;': 0.22; 'tests': 0.22; '&gt;': 0.26; 'supported': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'thus': 0.29; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; 'membership': 0.31; 'another': 0.32; 'worked': 0.33; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'next': 0.36; 'should': 0.36; 'checks': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'space': 0.40; 'even': 0.60; 'entire': 0.61; 'first': 0.61; 'hundred': 0.95
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 :content-type; bh=wFqnM1tNxAXrp4BNMI5b4i1MU8XwXHunvJbBvuG8PIg=; b=lZYZFqqrgghq5eI6SLwXLMyeF+vrZBV7MCKq6AM7yRVKTJqFFZjS9YHDc1+vAcKdmq 5kO5DDrPrfvbNSXOWjWecvGb863UAQbHUDcKRkCkAunClg8n2vO2c1v6nO5AZ9Mva++Y MAn3V87i2WNnDMo/IFS0qA2ESURVAHedi4jBixErp9p62aGEZls7VHYsz1O7+EO4t5jw FH0LVGqcEpTlVmTc7o9Pi/lvA4KTp2U7jtY4lMNUHHsVoSD91n2yyIfXdpKXQLm60X/u 6o9lmZJOc+YP6krllKxHHJjRqc0fMuIu4/yJTE8zDvVzXRbUSwF92tAG1lzYas909GkH cvOg==
X-Received by 10.68.241.130 with SMTP id wi2mr4219510pbc.89.1418195678655; Tue, 09 Dec 2014 23:14:38 -0800 (PST)
MIME-Version 1.0
In-Reply-To <CAPTjJmrM_nrGhPn2Le7b0iDOL5V035SOE3kVg98_89dVjueynA@mail.gmail.com>
References <20141210052025.GA84184@FuzzyHorror> <CAPTjJmrM_nrGhPn2Le7b0iDOL5V035SOE3kVg98_89dVjueynA@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 10 Dec 2014 00:13:58 -0700
Subject Re: Nested loops is strangely slow, totally at a loss.
To Python <python-list@python.org>
Content-Type multipart/alternative; boundary=047d7b339d0da5fb430509d769d9
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.16799.1418195682.18130.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1418195682 news.xs4all.nl 2875 [2001:888:2000:d::a6]:54790
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:82267

Show key headers only | View raw


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

On Tue, Dec 9, 2014 at 11:30 PM, Chris Angelico <rosuav@gmail.com> wrote:
> Are you sure it isn't? Your 'space' is an iterable cubic
> cross-product. Your first loop checks (0,0,0) which is the first
> element returned, and is thus fast... but it also *consumes* that
> first element. The next time you test it, the entire space gets
> consumed, looking for another (0,0,0), which won't exist. That means
> iterating over 580**3 == 195112000 (two hundred million) tuples, and
> that *is* going to be slow.

Huh, I wasn't even aware that membership tests worked on iterables with no
__contains__ method. Seems odd to me that 'x in y' should be supported but
not 'len(y)'.

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


Thread

Re: Nested loops is strangely slow, totally at a loss. Ian Kelly <ian.g.kelly@gmail.com> - 2014-12-10 00:13 -0700

csiph-web