Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Antoon Pardon Newsgroups: comp.lang.python Subject: Re: how to convert code that uses cmp to python3 Date: Fri, 8 Apr 2016 15:31:58 +0200 Lines: 41 Message-ID: References: <57064D0D.1030701@rece.vub.ac.be> <5706C961.2000009@rece.vub.ac.be> <57075F43.7060004@rece.vub.ac.be> <85fuuw5ypl.fsf@benfinney.id.au> <5707B2CE.1010407@rece.vub.ac.be> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de wqu+NOLmD5TMoOsUWwG5xAgLNuZvnVKb8OdE0F7N/2Fw== 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; 'python3': 0.05; 'received:134': 0.05; 'granted,': 0.07; 'subject:code': 0.07; 'worse': 0.09; 'python': 0.10; 'things.': 0.15; 'iterating': 0.16; 'measured': 0.16; 'received:ac.be': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'seconds.': 0.16; 'subject:python3': 0.16; 'worse.': 0.16; 'worst': 0.16; 'comparing': 0.18; 'changes': 0.20; 'delta': 0.22; 'object.': 0.22; 'code,': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'module.': 0.27; 'sequence': 0.27; 'comparison': 0.29; 'forces': 0.29; 'subject:that': 0.29; 'code': 0.30; 'received:be': 0.30; 'changing': 0.34; 'list': 0.34; 'done': 0.35; 'follows:': 0.35; 'returning': 0.35; 'something': 0.35; 'but': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'doing': 0.38; 'difference': 0.38; 'times.': 0.38; 'test': 0.39; 'takes': 0.39; 'to:addr:python.org': 0.40; 'some': 0.40; 'different': 0.63; 'between': 0.65; 'results.': 0.67; '100': 0.79; 'change?': 0.84; 'comparable': 0.84; 'measure.': 0.84; 'optimized.': 0.84; 'pardon': 0.84; 'schreef': 0.84; 'same,': 0.91 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Al0LABCyB1eGuA9G/2dsb2JhbABchFMBM7xGhg0CggABAQEBAQFmhGkBAQQjVRELGgIFFgsCAgkDAgECAUUTBgICiCOuVI0mhFoBAQgCHnyFJYRLhQuCNIJWBZMZhGuBVIw4iSuFYo8lYoNpagGJOAEBAQ User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.7.0 In-Reply-To: <85fuuw5ypl.fsf@benfinney.id.au> 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: , X-Mailman-Original-Message-ID: <5707B2CE.1010407@rece.vub.ac.be> X-Mailman-Original-References: <57064D0D.1030701@rece.vub.ac.be> <5706C961.2000009@rece.vub.ac.be> <57075F43.7060004@rece.vub.ac.be> <85fuuw5ypl.fsf@benfinney.id.au> Xref: csiph.com comp.lang.python:106677 Op 08-04-16 om 09:47 schreef Ben Finney: > Antoon Pardon writes: > >> But it was already working and optimized. The python3 approach forces >> me to make changes to working code and make the performance worse. > Yes, changing from Python 2 to Python 3 entails changing working code, > and entails different implementations for some things. > > As for worse performance, that is something you can objectively measure. > What is the size of the performance reduction you have objectively > measured from this change? Well having a list of 1000 Sequence like object. Each sequence containing between 1 and 100 numbers. Comparing each sequence to each other a 100 times. I get the following results. Doing it as follows: seq1 < seq2 seq2 < seq1 takes about 110 seconds. Doing it like this: delta = cmp(seq1, seq2) delta < 0 delta > 0 takes about 50 seconds. Comparing was done by just iterating over the two sequences and the first time both numbers were not the same, returning the difference of the numbers Granted, this test just lifted the comparison code from the module. What was interesting was that the worst case in python3 was comparable to the better case in python2. -- Antoon.