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 18:09:42 +1000 Lines: 110 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> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de EGNBiK50en9BNnX3kf+QrgLD8qnfP5UlhTOzB+hJc9kQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'objects,': 0.07; 'pypy': 0.07; 'wednesday,': 0.07; 'cc:addr:python-list': 0.09; 'variance': 0.09; 'example:': 0.10; 'python': 0.10; '2.7': 0.13; 'wed,': 0.15; 'wednesday': 0.15; '--version': 0.16; '2016': 0.16; '328': 0.16; '337': 0.16; '339': 0.16; '343': 0.16; '478': 0.16; 'adam': 0.16; 'distinction': 0.16; 'dropping': 0.16; 'expected,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'integers.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'renaming': 0.16; 'wrote:': 0.16; 'case.': 0.18; 'comparing': 0.18; 'debugging': 0.18; 'integer': 0.18; 'language': 0.19; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'machine': 0.21; '(on': 0.22; 'gcc': 0.22; 'lawrence': 0.22; 'visible': 0.22; 'fit': 0.23; 'bigger': 0.23; 'consistent': 0.23; 'words': 0.24; 'header:In-Reply-To:1': 0.24; 'sort': 0.25; "doesn't": 0.26; 'message-id:@mail.gmail.com': 0.27; '3.0': 0.27; 'said,': 0.27; 'this.': 0.28; 'looks': 0.29; '100000': 0.29; 'comparison': 0.29; 'dramatic': 0.29; 'python2.7': 0.29; 'system,': 0.30; 'creating': 0.30; 'supposed': 0.31; 'probably': 0.31; 'compiled': 0.32; 'options': 0.33; 'problem': 0.33; 'builds': 0.33; "d'aprano": 0.33; 'int': 0.33; 'steven': 0.33; '(for': 0.34; 'add': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'quite': 0.35; 'something': 0.35; 'skip:p 30': 0.35; 'but': 0.36; 'there': 0.36; '(and': 0.36; 'faster': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'setting': 0.37; 'one,': 0.37; 'starting': 0.37; 'things': 0.38; 'creation': 0.38; 'skip:p 20': 0.38; 'does': 0.39; 'skip:x 10': 0.40; 'some': 0.40; 'ever': 0.60; 'your': 0.60; 'back': 0.62; 'per': 0.62; 'more': 0.63; 'different': 0.63; 'necessarily': 0.63; 'latest': 0.64; 'within': 0.64; 'between': 0.65; '10000': 0.66; 'picked': 0.66; 'here': 0.66; 'today.': 0.67; '100': 0.79; '356': 0.84; '5.3.1': 0.84; 'bignums': 0.84; 'bignums,': 0.84; 'chrisa': 0.84; 'comparable': 0.84; 'to:none': 0.91; 'hand,': 0.97 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 :content-transfer-encoding; bh=xIfm/b1nZo/x7ptoJcMJ3Ah2OMvYUIMQFX4GBY8sRzY=; b=zJhQlQIfN3T6JjLbtu6mrbQHhspAJHAYLfiIPEAJwphci5iCEr8RpL+yP3WOWFvaX/ OzNo78lunQGEj3M5xotNyxvxviBEUm421cqVQaGoRjRUkR4+u1Ma1/GoraxYxKZZbPLD K/fM4YGwt2EIi/3opYQx4HfKC7T9gGa8ISEzmzFynI/QHc2q8RIJmXLaK+U6ciHXpPMn bNs+FoHlbsXHPR3OnenMeo9tX3nO52HNUHYu4XOeWYc4yHdOW5o6lsl2FWMZlpZK63Mo q1cfJp+G0mMH2e7Ei1ul4rPRotn942N+W2Bwi9w1DQtCVcxClGPEADG2sH2sDO642ZTm CsVQ== 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:content-transfer-encoding; bh=xIfm/b1nZo/x7ptoJcMJ3Ah2OMvYUIMQFX4GBY8sRzY=; b=KHx3iOeN21MjMBTS8GnNsseFEKN/TDF88vguGtcEEQpuXunDbgf2Ty68D1pPA/87DV aMsPaJXnarbECAduJo9sDVzz0AVd4tWzAuFNMhXv4wT9Y6IkrDUY597GzRqgfCqkgI/h QJmZ1g+SC91fav1VUClH3YnOJxG0aODkDh/mvu3Ka3GgACgfTjQU8PsqtEijuIZHXaQy lXvqyR2VfrLN8y5VZDuiUK1apqnHk/ftP+RB+glbWYn0l95wbKPou1MseSTu1HT58zIt H69py04CLTQ/uJ2W3pHD1YLx5Fm2fn1CLshFDUlmreAxC17R0cQ6L7PMRl95kTRfdGZk Ay/g== X-Gm-Message-State: ALyK8tIczhlUo/mrNJhasfUhdlD8sXytjcrG9isMPVQiYxiZbpNzq/ZTTmrkZ1hXMd7VHMZq0WTlg3A7+FwmJg== X-Received: by 10.194.97.201 with SMTP id ec9mr6957415wjb.117.1467187784386; Wed, 29 Jun 2016 01:09:44 -0700 (PDT) In-Reply-To: <57736ea1$0$2933$c3e8da3$76491128@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> Xref: csiph.com comp.lang.python:110760 On Wed, Jun 29, 2016 at 4:45 PM, Steven D'Aprano wrote: > On Wednesday 29 June 2016 15:51, Lawrence D=E2=80=99Oliveiro wrote: > >> On Wednesday, June 29, 2016 at 5:26:46 PM UTC+12, Steven D'Aprano wrote: >>> BUT in Python 3, the distinction between int and long is gone by droppi= ng >>> int and renaming long as "int". So all Python ints are BIGNUMs. >> >> I don=E2=80=99t understand what the problem is with this. Is there suppo= sed to be >> some issue with performance? Because I can=E2=80=99t see it. > > If there is a performance hit, it's probably pretty small. It may have be= en > bigger back in Python 3.0 or 3.1. > > [steve@ando ~]$ python2.7 -m timeit -s "n =3D 0" "for i in xrange(10000):= n +=3D i" > 100 loops, best of 3: 1.87 msec per loop > > [steve@ando ~]$ python3.3 -m timeit -s "n =3D 0" "for i in range(10000): = n +=3D i" > 1000 loops, best of 3: 1.89 msec per loop > > > Although setting debugging options does make it pretty slow: > > [steve@ando ~]$ python/python-dev/3.6/python -m timeit -s "n =3D 0" "for = i in > range(10000): n +=3D i" > 100 loops, best of 3: 13.7 msec per loop That's not necessarily fair - you're comparing two quite different Python interpreters, so there might be something entirely different that counteracts the integer performance. (For example: You're creating and disposing of large numbers of objects, so the performance of object creation could affect things hugely.) To make it somewhat fairer, add long integer performance to the mix. Starting by redoing your test: rosuav@sikorsky:~$ python2.7 -m timeit -s "n =3D 0" "for i in xrange(10000): n +=3D i" 10000 loops, best of 3: 192 usec per loop rosuav@sikorsky:~$ python2.7 -m timeit -s "n =3D 1<<100" "for i in xrange(10000): n +=3D i" 1000 loops, best of 3: 478 usec per loop rosuav@sikorsky:~$ python3.4 -m timeit -s "n =3D 0" "for i in range(10000): n +=3D i" 1000 loops, best of 3: 328 usec per loop rosuav@sikorsky:~$ python3.4 -m timeit -s "n =3D 1<<100" "for i in range(10000): n +=3D i" 1000 loops, best of 3: 337 usec per loop rosuav@sikorsky:~$ python3.5 -m timeit -s "n =3D 0" "for i in range(10000): n +=3D i" 1000 loops, best of 3: 369 usec per loop rosuav@sikorsky:~$ python3.5 -m timeit -s "n =3D 1<<100" "for i in range(10000): n +=3D i" 1000 loops, best of 3: 356 usec per loop rosuav@sikorsky:~$ python3.6 -m timeit -s "n =3D 0" "for i in range(10000): n +=3D i" 1000 loops, best of 3: 339 usec per loop rosuav@sikorsky:~$ python3.6 -m timeit -s "n =3D 1<<100" "for i in range(10000): n +=3D i" 1000 loops, best of 3: 343 usec per loop (On this system, python3.4 and python3.5 are Debian-shipped builds of CPython, and python3.6 is one I compiled from hg today. There's no visible variance between them, but just in case. I don't have a python3.3 on here for a fair comparison with your numbers, sorry.) The way I read this, Python 2.7 is noticeably slower with bignums, but visibly faster with machine words. Python 3, on the other hand, has consistent performance whether the numbers fit within a machine word or not - which is to be expected, since it uses bignums for all integers. PyPy's performance shows an even more dramatic gap: rosuav@sikorsky:~$ pypy -m timeit -s "n =3D 0" "for i in xrange(10000): n += =3D i" 100000 loops, best of 3: 7.59 usec per loop rosuav@sikorsky:~$ pypy -m timeit -s "n =3D 1<<100" "for i in xrange(10000): n +=3D i" 10000 loops, best of 3: 119 usec per loop rosuav@sikorsky:~$ pypy --version Python 2.7.10 (5.1.2+dfsg-1, May 17 2016, 18:03:30) [PyPy 5.1.2 with GCC 5.3.1 20160509] Sadly, Debian doesn't ship a pypy3 yet, so for consistency, I picked up the latest available pypy2 and pypy3 from pypy.org. rosuav@sikorsky:~/tmp$ pypy2-v5.3.1-linux64/bin/pypy -m timeit -s "n =3D 0" "for i in xrange(10000): n +=3D i" 100000 loops, best of 3: 7.58 usec per loop rosuav@sikorsky:~/tmp$ pypy2-v5.3.1-linux64/bin/pypy -m timeit -s "n =3D 1<<100" "for i in xrange(10000): n +=3D i" 10000 loops, best of 3: 115 usec per loop rosuav@sikorsky:~/tmp$ pypy3.3-v5.2.0-alpha1-linux64/bin/pypy3 -m timeit -s "n =3D 0" "for i in range(10000): n +=3D i" 100000 loops, best of 3: 7.56 usec per loop rosuav@sikorsky:~/tmp$ pypy3.3-v5.2.0-alpha1-linux64/bin/pypy3 -m timeit -s "n =3D 1<<100" "for i in range(10000): n +=3D i" 10000 loops, best of 3: 115 usec per loop Performance comparable to each other (and to the Debian-shipped one, which is nice - as Adam Savage said, I love consistent data!), and drastically different between machine words and bignums. So it looks like PyPy *does* have some sort of optimization going on here, without ever violating the language spec. ChrisA