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: 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 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> In-Reply-To: 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 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: 1416962800 news.xs4all.nl 2842 [2001:888:2000:d::a6]:37934 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81532 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