Path: csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Pyhon 2.x or 3.x, which is faster? Date: Tue, 8 Mar 2016 12:49:47 +1100 Lines: 44 Message-ID: References: <87d1r6iltx.fsf@elektro.pacujo.net> <56de2c36$0$1607$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de dm8vT1tdUPSzTOrh4CnQ/ACcRjnbzdGzo3LV4Cp8i+tw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python,': 0.02; 'cpython': 0.05; 'cc:addr:python-list': 0.09; 'jpg': 0.09; 'slow.': 0.09; 'subject:which': 0.09; 'sucks': 0.09; 'python': 0.10; 'python.': 0.11; 'files.': 0.13; '"python': 0.16; '2016': 0.16; 'certainly.': 0.16; 'chris,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'naive': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'saying.': 0.16; 'uses,': 0.16; 'wrote:': 0.16; 'memory': 0.17; 'byte': 0.18; 'comparing': 0.18; 'library,': 0.18; 'library': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'saying': 0.22; 'am,': 0.23; 'code.': 0.23; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'sort': 0.25; "i've": 0.25; 'chris': 0.26; 'point.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'data,': 0.27; 'actual': 0.28; 'interface': 0.29; 'use?': 0.29; "i'm": 0.30; 'that.': 0.30; 'code': 0.30; 'probably': 0.31; "can't": 0.32; 'run': 0.33; "d'aprano": 0.33; 'done,': 0.33; "he's": 0.33; 'sat': 0.33; 'steven': 0.33; 'tue,': 0.34; 'running': 0.34; 'received:google.com': 0.35; 'trouble': 0.35; 'could': 0.35; 'acceptable': 0.35; 'quite': 0.35; 'something': 0.35; "isn't": 0.35; 'but': 0.36; 'too': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'others.': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'done.': 0.37; 'received:209.85.213': 0.37; 'doing': 0.38; 'front': 0.38; 'received:209': 0.38; 'anything': 0.38; 'files': 0.38; 'sure': 0.39; 'whatever': 0.39; 'takes': 0.39; 'still': 0.40; 'some': 0.40; 'ten': 0.60; 'real': 0.62; 'programs': 0.62; 'back': 0.62; 'improved': 0.63; 'more': 0.63; 'necessarily': 0.63; 'profile': 0.63; 'times': 0.63; 'mar': 0.65; 'here': 0.66; 'production': 0.67; 'day': 0.67; 'analysis': 0.72; 'quality': 0.72; 'heavy': 0.81; 'benchmark': 0.84; 'chrisa': 0.84; 'done:': 0.84; 'faster.': 0.84; 'gig': 0.84; "it'd": 0.84; 'to:none': 0.91; 'hundred': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=PA5iD1SBW5Btjwowx4JSlj3jvP83U3ozcJ1e5LedLOI=; b=tCiIbq/5wyjBfNtxgC596+dWBzWrj4l+d/Rc6QaoWhSSm4cbR6jTWuBSaXVr1Dz/JE VPpTVI/y6UI173MDFmzUU0aiQLZJAoBdfyPSqHrtNVbSL+v3zecdgXarXHvspITZ8Og7 5uP4F08P4KZvNkxR5iNw3Sza3blCk5NhN1ZiebmUfeEKjGS35K9eY1rW+NYsDaqqnF7B cvkeRTdze0Ig7rRKHwYMD8lTqNywDhsolQm3qjOLomD/FRa7+hp7ap10tUdWcNKJAFbb XUs+oEWDfLM7qdZ6gUPnKAy/bzOOmj3Ti6hVluqVX/aKC+uVGSCY/JqmVjU9APJ8GiVY Ih9g== 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:date :message-id:subject:from:cc; bh=PA5iD1SBW5Btjwowx4JSlj3jvP83U3ozcJ1e5LedLOI=; b=EWxZGvLGrCU78ayoIHZuztOaArPApT/O/cGMWKO8T2Rsjr446e4BrAHZA1sRQOy2Jk laaNVPu7migGlJ+ZtTITp2Q3YuMNSVmCypwk5dQtVzNMlS0FwU7JeVVPKhRYPA6Q4tTG vpLy1AkVh/zzju34jX5VGotx7l3rGCtA1a7dav3VtPEdJIicTMUd92txgyCbYth4iIei 4yVY/MI0yAomEhKrwr7sGEToyjUf085RKs9SzPkQgz2bGs1QdO0F4erT20khwxWaTCSP VKgbCCWbyNuTbejbyF6ODDioy6G1w83fqTj//ERW2EZ4A1EX5INwvPm79BVBX0FkmzMV XGag== X-Gm-Message-State: AD7BkJJSBBd/eZLaYfevxxIBmPhz5jJxIxzydkz4iOnuXeU3KtY1bIgXGaRtSsFgCRk4Ri6vkbr1YH+dwvQBmA== X-Received: by 10.50.137.35 with SMTP id qf3mr15921930igb.92.1457401787170; Mon, 07 Mar 2016 17:49:47 -0800 (PST) In-Reply-To: <56de2c36$0$1607$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104306 On Tue, Mar 8, 2016 at 12:34 PM, Steven D'Aprano wrote: > On Tue, 8 Mar 2016 07:47 am, Chris Angelico wrote: > >> You write *real world* code and then profile that. You get actual real >> programs that you actually really use, and you run those through >> timing harnesses. > > > Chris, I think that's exactly what BartC has done: he has a program that he > actually uses, one which processes JPG files. It's written in pure Python, > so he's not comparing the quality of C libraries, he's comparing Python > versus Python. The trouble is that we can't be sure _what_ he's done. All we have is that it takes longer under some circumstances than others. Without knowing a lot more about how the measurements are done, I don't know that we can get anything from it. And I remember seeing a performance analysis that showed that array.array() actually sucks for performance; hence my recommendation to try other ways of doing things, before saying "Python 3 is slower than Python 2". > Could Bart's code be improved for production use? Almost certainly. I'm sure > that by using a C image processing library, like pillow, it would be ten or > a hundred times faster. If Bart were saying "Python is crap, it's too slow" > then a perfectly acceptable response would be "no, you're just misusing it, > here you want to use it as an interface to this library and let the library > do the heavy lifting". That's what Python is designed for. But that's not > what Bart is saying. > > I'm impressed that pure Python code running in CPython is even *usable* for > whatever sort of image processing BartC is doing. He must be doing > something right, given that its not unusably slow. Fair point. Although these are only small files (as far as I know), so even if there's an O(N**2) memory allocation (eg with a naive "take a byte off the front and give me back the rest" algorithm), it'd quite probably still be usable. I've had N Squareds in code that sat there until the day I did some stupid benchmark on a gig of data, and only then started seeing problems. Readably-written code isn't necessarily that much slower than tightly-optimized code. ChrisA