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


Groups > comp.lang.python > #81532

Re: Challenge: optimizing isqrt

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.097
X-Spam-Evidence '*H*': 0.81; '*S*': 0.00; 'argument': 0.05; 'lines,': 0.07; 'assuming': 0.09; '(about': 0.16; 'interest,': 0.16; 'processor,': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'slightly': 0.19; 'header:User-Agent:1': 0.23; "aren't": 0.24; 'earlier': 0.24; 'looks': 0.24; 'supported': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'bigger': 0.30; 'too.': 0.31; '20%': 0.31; 'faster,': 0.31; 'oversight': 0.31; 'test': 0.35; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'really': 0.36; 'skip:\xd0 10': 0.36; 'shows': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'matter': 0.61; 'become': 0.64; 'total': 0.65; 'worth': 0.66; 'received:74.208': 0.68; '8bit%:94': 0.72; '10%': 0.74; '8bit%:43': 0.74; '2.7.': 0.84; 'faster.': 0.84; 'measurable': 0.84
Date Tue, 25 Nov 2014 19:46:21 -0500
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Challenge: optimizing isqrt
References <54543787$0$13005$c3e8da3$5496439d@news.astraweb.com> <m4la9e$5hl$1@ger.gmane.org> <CAP=-cKWj5yeL34GG5ay4v-V9i6nuTgF3VvmC8=PDOYruwp8q5Q@mail.gmail.com> <m52lhi$4sq$1@ger.gmane.org>
In-Reply-To <m52lhi$4sq$1@ger.gmane.org>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-Provags-ID V02:K0:z7pcxFY6b0gVpXa1Slq486rJgR+V62E23SfGG5uIbEf n/BPPeq31wEs6I4CxYO2MboJlsTByzV0GaAEFd90WzDkV8vzdy vkSe50pM1tQu2mLzI23xO0li3P/KC6M2byMa6fMlc/vrh6BUun BjjQnZtC4YacaaYrlZZV22ceIv9w2m+kajzmWsZ1HVDHaZLNOe poN1NoN/+GnQBWNj7s2n0LPdH4BDJURx5s/TG1JQxs+gZHKVsg AXnHJ1tmAL42Ba6lpRIDV7MNwK0G+IiDNT8Dd8kSMBTzZxWk8t Tuv9xDUnPG5XlsdOkri4U5CZvKbOrrahley7hEYv0VbwGFlCZP yTEqNxRl6gAyZ9i9FcTE=
X-UI-Out-Filterresults notjunk:1;
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.16299.1416962800.18130.python-list@python.org> (permalink)
Lines 34
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1416962800 news.xs4all.nl 2842 [2001:888:2000:d::a6]:37934
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:81532

Show key headers only | View raw


On 11/25/2014 02:31 PM, Serhiy Storchaka wrote:
> п'ятниця, 21-лис-2014 08:15:57 ви написали:
>> This looks very good indeed. As a matter of interest, is there any
>> particular reason you have used 2*b instead of b+b? Might b+b be faster
>> than b*2?
>
> Yes, it is slightly faster, but the effect is indiscernible in total
> time. But
> there is not harm to use b+b.
>
>> Also, in various lines, you use //2. Would >>1 be quicker? On reflection,
>> perhaps you have had to use //2 because >>1 cannot be used in those
>> situations.
>
> I thought this effect would be insignificant too. But actually it is
> measurable
> (about 10% for some input). Thanks, this optimization is worth to be
> applied.
>

Unfortunately, for many values, the version of the function with >>1 is 
slower.  It's only when the argument is bigger than 10**40 that it's as 
much as 1% faster.  But it's true that for really large values, it's 
quicker.

A quick test shows that 3.3 is about 20% faster for both these functions 
than 2.7.

My oversight earlier was assuming a native type.  Once you get into 
"longs" which aren't supported by the processor, the shift will likely 
become much faster than divide.

-- 
DaveA

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


Thread

Challenge: optimizing isqrt Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-01 12:29 +1100
  Re: Challenge: optimizing isqrt Chris Angelico <rosuav@gmail.com> - 2014-11-01 13:12 +1100
  Re: Challenge: optimizing isqrt Christian Gollwitzer <auriocus@gmx.de> - 2014-11-01 09:02 +0100
    Re: Challenge: optimizing isqrt Christian Gollwitzer <auriocus@gmx.de> - 2014-11-01 09:09 +0100
    Re: Challenge: optimizing isqrt Chris Angelico <rosuav@gmail.com> - 2014-11-01 19:13 +1100
      Re: Challenge: optimizing isqrt Christian Gollwitzer <auriocus@gmx.de> - 2014-11-01 09:25 +0100
        Re: Challenge: optimizing isqrt Chris Angelico <rosuav@gmail.com> - 2014-11-01 19:33 +1100
          Re: Challenge: optimizing isqrt Christian Gollwitzer <auriocus@gmx.de> - 2014-11-01 09:38 +0100
            Re: Challenge: optimizing isqrt Chris Angelico <rosuav@gmail.com> - 2014-11-01 19:45 +1100
  Re: Challenge: optimizing isqrt Akira Li <4kir4.1i@gmail.com> - 2014-11-01 12:12 +0300
  Re: Challenge: optimizing isqrt Serhiy Storchaka <storchaka@gmail.com> - 2014-11-20 20:00 +0200
  Re: Challenge: optimizing isqrt Stephen Tucker <stephen_tucker@sil.org> - 2014-11-21 08:15 +0000
  Re: Challenge: optimizing isqrt Dave Angel <davea@davea.name> - 2014-11-23 10:43 -0500
  Re: Challenge: optimizing isqrt Serhiy Storchaka <storchaka@gmail.com> - 2014-11-25 21:31 +0200
  Re: Challenge: optimizing isqrt Dave Angel <davea@davea.name> - 2014-11-25 19:46 -0500
  Re: Challenge: optimizing isqrt Stephen Tucker <stephen_tucker@sil.org> - 2014-11-26 07:57 +0000
    Re: Challenge: optimizing isqrt Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-26 21:25 +1100
  Re: Challenge: optimizing isqrt Serhiy Storchaka <storchaka@gmail.com> - 2014-11-26 18:24 +0200

csiph-web