Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Assignment Versus Equality Date: Wed, 29 Jun 2016 23:34:48 +1000 Lines: 40 Message-ID: References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> <311c9890-8588-45f1-85a3-478e18268508@googlegroups.com> <57736ea1$0$2933$c3e8da3$76491128@news.astraweb.com> <5773c0b5$0$1608$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de LHaDO8WGsFrsv5Gw2illmwtHL+Ifn37P3M0TTjyEibYA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'run,': 0.07; 'cc:addr :python-list': 0.09; 'x86_64': 0.09; 'python': 0.10; 'wed,': 0.15; "(you're": 0.16; '2016': 0.16; '478': 0.16; 'bigger.': 0.16; 'digits.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'uname': 0.16; 'unfair': 0.16; 'wrote:': 0.16; 'obviously': 0.16; "shouldn't": 0.18; '(in': 0.18; 'tests': 0.18; 'runs': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'performing': 0.23; 'header:In-Reply-To:1': 0.24; 'all.': 0.24; 'linux': 0.26; 'message-id:@mail.gmail.com': 0.27; 'values': 0.28; 'python2.7': 0.29; 'compared': 0.30; "d'aprano": 0.33; 'steven': 0.33; "i'll": 0.33; 'running': 0.34; 'received:google.com': 0.35; 'so,': 0.35; 'mine': 0.35; "isn't": 0.35; 'but': 0.36; 'there': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'skip:4 10': 0.38; 'skip:x 10': 0.40; 'your': 0.60; 'per': 0.62; 'different': 0.63; '10000': 0.66; 'virtually': 0.66; 'bignums': 0.84; 'chrisa': 0.84; 'smp': 0.84; 'too:': 0.84; 'absolutely': 0.88; 'to:none': 0.91; 'same,': 0.91 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:cc; bh=DIctQv0dwNSvAUd6i81dnujGxqkxPii53M1eFhBQFmQ=; b=XyhvT4vcKnbCD5qoomoGBJ1qSPsLJY88kYT1TOFugytEzEBtxxhMc3v/92z4NINpIm TjzOEHE8E6GNnGVd3XsDpDyFDQICI23E8GjdXViCAy/b7IuP++DWbeQKxnP94YNXe1vl ZGGvHnfoPtdRxc3gNbfAtnmOOpLQt3+5lr+NNK92WqnRl1UdD6M4pOIEiuAI7Ln3erMN Lkhym+U6xvALZbXjM4xwXVkS89UUTkIHzl2xpOKy1QPJj1oYI8RjpsdG9Lac4LKEWJcD zqMt0mPMLm9nCgM+2bLsErRn1SbcMSlC25cQ5A6/UH5xA6NvUuVkSMF1lOuv4BoaFF2u F96A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:cc; bh=DIctQv0dwNSvAUd6i81dnujGxqkxPii53M1eFhBQFmQ=; b=JwvK9DfHvO0lfCV8tuvUOC+kod4nKn6AeHcSL2KpmUbZl8ajsNgXi9SQmQiiHUWKAV D8z+NL972590VljVNXeojxxvsfYDzczgYfdfNrqk2Y52HFZKz4gwoH4cFjiDDGX1HxJx wRKAtT+B0FuaUz55gy+YiuPBMKLoFn8nTNpbQ+x+WA8YDDB/HW3VIXuVioUorXLNpLS7 igrU3FM57J2mZ2KVFJMY2ggvbhTrBHjr776R0HY5CmWwROp0GZoPouN2TjuIDvQ4LMqq Mjuh5RLyE4oUGQ2vuSqXjQYlN4J1+lun2x1rBk9KjkCWZ0veA1bKJM+IPkfJFC9GdInZ y7Wg== X-Gm-Message-State: ALyK8tKPuUvbTOI1vn/fz77aRaMcIUqKkz5EiaQjv+PHii3dB19QtWl9VwA727j4vxwFA7lmVrJIbJ/6DJX2nQ== X-Received: by 10.28.30.149 with SMTP id e143mr8842257wme.81.1467207290565; Wed, 29 Jun 2016 06:34:50 -0700 (PDT) In-Reply-To: <5773c0b5$0$1608$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <8a53c069-ca13-47bf-a24e-d2393a018b22@googlegroups.com> <4e72d24b-07b4-484c-83f8-a1fecc727f8c@googlegroups.com> <5773340f$0$1616$c3e8da3$5496439d@news.astraweb.com> <34aa9c69-cdd5-437c-a32b-9a706ef6d9c0@googlegroups.com> <57735c0a$0$2864$c3e8da3$76491128@news.astraweb.com> <311c9890-8588-45f1-85a3-478e18268508@googlegroups.com> <57736ea1$0$2933$c3e8da3$76491128@news.astraweb.com> <5773c0b5$0$1608$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:110778 On Wed, Jun 29, 2016 at 10:36 PM, Steven D'Aprano wrote: >> rosuav@sikorsky:~$ python2.7 -m timeit -s "n = 0" "for i in >> xrange(10000): n += i" >> 10000 loops, best of 3: 192 usec per loop >> rosuav@sikorsky:~$ python2.7 -m timeit -s "n = 1<<100" "for i in >> xrange(10000): n += i" >> 1000 loops, best of 3: 478 usec per loop > > Now *that's* an unfair benchmark, because we know that BigNums get slower as > they get bigger. A BigNum with 30+ digits is not going to perform like a > BigNum with 8 digits. On its own, perhaps. But then I do the exact same tests on Python 3, and the numbers are virtually identical - suggesting that the bignum slowdown isn't all that significant at all. But in case you're worried, I'll do it your way too: rosuav@sikorsky:~$ python2.7 -m timeit -s "n = 0" "for i in xrange(10000): n += i" 10000 loops, best of 3: 192 usec per loop rosuav@sikorsky:~$ python2.7 -m timeit -s "n = 1<<100" "for i in xrange(10000): n += i" 1000 loops, best of 3: 476 usec per loop rosuav@sikorsky:~$ python2.7 -m timeit -s "n = 0L" "for i in xrange(10000): n += i" 1000 loops, best of 3: 476 usec per loop So, once again, my system shows that there's a definite slowdown from using bignums - and it's the same whether I start with 1<<100 or 0L. (In this particular run, absolutely precisely the same, but other runs showed numbers like 479 and 486.) What's different about your system that you see short ints as performing exactly the same as long ints? Obviously you're running on a slower computer than mine (you're seeing msec values compared to my usec), but that shouldn't be significant. Is there a massive architectural difference? rosuav@sikorsky:~$ uname -a Linux sikorsky 4.6.0-1-amd64 #1 SMP Debian 4.6.1-1 (2016-06-06) x86_64 GNU/Linux ChrisA