how to convert code that uses cmp to python3

Antoon Pardon antoon.pardon at rece.vub.ac.be
Fri Apr 8 09:31:58 EDT 2016


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




More information about the Python-list mailing list