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: 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>': 0.22; 'tests': 0.22; '>': 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: References: <20141210052025.GA84184@FuzzyHorror> From: Ian Kelly Date: Wed, 10 Dec 2014 00:13:58 -0700 Subject: Re: Nested loops is strangely slow, totally at a loss. To: Python 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 --047d7b339d0da5fb430509d769d9 Content-Type: text/plain; charset=UTF-8 On Tue, Dec 9, 2014 at 11:30 PM, Chris Angelico 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)'. --047d7b339d0da5fb430509d769d9 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Tue, Dec 9, 2014 at 11:30 PM, Chris Angelico <rosuav@gmail.com> wrote:
> Are y= ou sure it isn't? Your 'space' is an iterable cubic
> cro= ss-product. Your first loop checks (0,0,0) which is the first
> eleme= nt 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
> ite= rating over 580**3 =3D=3D 195112000 (two hundred million) tuples, and
&g= t; that *is* going to be slow.

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