Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed4a.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.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'algorithm': 0.04; 'cache': 0.07; 'bytes,': 0.09; 'caching,': 0.09; 'counting': 0.09; 'difference,': 0.09; 'imply': 0.09; 'logic': 0.09; 'seemed': 0.09; 'python': 0.11; "wouldn't": 0.14; 'binary,': 0.16; 'blocks': 0.16; 'boundary.': 0.16; 'threshold': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'bit': 0.19; 'differ': 0.19; 'seems': 0.21; 'machine': 0.22; 'memory': 0.22; 'header:User-Agent:1': 0.23; 'bytes': 0.24; 'fairly': 0.24; 'versions': 0.24; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'bigger': 0.30; "i'm": 0.30; 'getting': 0.31; '100000': 0.31; '3.x': 0.31; 'long.': 0.31; 'with,': 0.31; "we're": 0.32; 'another': 0.32; 'subject:the': 0.34; 'could': 0.34; 'something': 0.35; 'one,': 0.35; 'but': 0.35; "i'll": 0.36; 'easily': 0.37; 'performance': 0.37; 'starting': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'dave': 0.60; 'up,': 0.60; 'numbers': 0.61; 'course': 0.61; "you're": 0.61; 'times': 0.62; 'more': 0.64; 'different': 0.65; 'taking': 0.65; 'size.': 0.65; 'charset:windows-1252': 0.65; 'between': 0.67; 'covers': 0.68; 'received:74.208': 0.68; 'results': 0.69; '2015': 0.84; '3.4': 0.84; 'guessed': 0.84; 'multiplying': 0.84; 'angel': 0.91 Date: Wed, 06 May 2015 10:22:56 -0400 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Throw the cat among the pigeons References: <87h9rvm576.fsf@Equus.decebal.nl> <55499304$0$12978$c3e8da3$5496439d@news.astraweb.com> <5549b41f$0$12927$c3e8da3$5496439d@news.astraweb.com> <554A1325.2060103@davea.name> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:yjoeTRoLkeAZeLy1D7XGbsFyUFy+EntqamG+PdnZN1rlHninZxr L5QuuNQFZUJANE+6oMHkpfnAX/3jfqiANMtHImLkp4ZYhRQbsIuvAsNQ+0Uk+LsauBptLFA kvPbi8BNTK5GM6teQmhfk/y4r7wLwEhubQ0eojhpyvFrWVUU4cFHcNfD3bQ4Y0xIc8rn4uL h79KpbL2pnjeRBDyG1MvA== X-UI-Out-Filterresults: notjunk:1; X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430922190 news.xs4all.nl 2901 [2001:888:2000:d::a6]:44931 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90058 On 05/06/2015 09:55 AM, Chris Angelico wrote: > On Wed, May 6, 2015 at 11:12 PM, Dave Angel wrote: >> I had guessed that the order of multiplication would make a big difference, >> once the product started getting bigger than the machine word size. >> >> Reason I thought that is that if you multiply starting at the top value (and >> end with multiplying by 2) you're spending more of the time multiplying >> big-ints. >> >> That's why I made sure that both Cecil's and my implementations were >> counting up, so that wouldn't be a distinction. >> >> I'm still puzzled, as it seems your results imply that big-int*int is faster >> than int*int where the product is also int. > > Are you using Python 2 or Python 3 for your testing? In Py3, there's > no type difference, and barely no performance difference as you cross > the word-size boundary. (Bigger numbers are a bit slower to work with, > but not hugely.) > Both Cecil and I are using 3.x I'm using 3.4 in particular. And I know int covers both big-int and int32. that's why I called it big-int, rather than long. I was, however, mistaken. it's not that threshold that we're crossing here, but another one, for MUCH larger numbers. factorial of 100000 and of 200000 have 456473 and 97350 digits, respectively. In binary, that would be about 190k bytes and 404k bytes, respectively. I was seeing factorial of 200000 taking about 4.5 times as long as factorial of 100000. All the other increments seemed fairly proportional. I'll bet the difference is something like the memory allocator using a different algorithm for blocks above 256k. Or the cache logic hitting a threshold. If it's caching, of course the threshold will differ wildly between machine architectures. If it's the memory allocator, that could easily vary between Python versions as well. -- DaveA