Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106677

Re: how to convert code that uses cmp to python3

From Antoon Pardon <antoon.pardon@rece.vub.ac.be>
Newsgroups comp.lang.python
Subject Re: how to convert code that uses cmp to python3
Date 2016-04-08 15:31 +0200
Message-ID <mailman.81.1460122331.2253.python-list@python.org> (permalink)
References (2 earlier) <5706C961.2000009@rece.vub.ac.be> <CAPTjJmrbL870mV1kU8nHar=bPyKZRmhKP-8iUs_tpYVo5vhhOA@mail.gmail.com> <57075F43.7060004@rece.vub.ac.be> <85fuuw5ypl.fsf@benfinney.id.au> <5707B2CE.1010407@rece.vub.ac.be>

Show all headers | View raw


Op 08-04-16 om 09:47 schreef Ben Finney:
> Antoon Pardon <antoon.pardon@rece.vub.ac.be> 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.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: how to convert code that uses cmp to python3 Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-04-08 15:31 +0200
  Re: how to convert code that uses cmp to python3 Marko Rauhamaa <marko@pacujo.net> - 2016-04-08 16:52 +0300
    Re: how to convert code that uses cmp to python3 Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-04-08 16:22 +0200

csiph-web