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


Groups > comp.lang.python > #106675

Re: how to convert code that uses cmp to python3

From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.lang.python
Subject Re: how to convert code that uses cmp to python3
Date 2016-04-08 15:52 +0300
Organization A noiseless patient Spider
Message-ID <87fuuwfejx.fsf@elektro.pacujo.net> (permalink)
References (2 earlier) <5706C961.2000009@rece.vub.ac.be> <85wpo95dpo.fsf@benfinney.id.au> <570761B2.3060800@rece.vub.ac.be> <mailman.71.1460101559.2253.python-list@python.org> <57079f03$0$1599$c3e8da3$5496439d@news.astraweb.com>

Show all headers | View raw


Steven D'Aprano <steve@pearwood.info>:

> I would be stunned if tuple comparisons with only a handful of values
> were slow enough that its worth caching their results with an
> lru_cache. But try it, and see how you go.

There are two ways your Python program can be slow:

 * You are doing something stupid like an O(exp(n)) when there is an
   O(n**2) available.

 * Python is inherently slower than C by a constant factor.

If you are doing something stupid, do refactor your code. But you
shouldn't try to make artificial optimizations to your code to make it
perform more like C. Write it in C, maybe partially, if you have to.

For example, your performance measurements might show that Python's
method calls are slow. That may be true but it is no invitation to
eliminate method calls from your code.


Marko

Back to comp.lang.python | Previous | NextPrevious 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 09:45 +0200
  Re: how to convert code that uses cmp to python3 Steven D'Aprano <steve@pearwood.info> - 2016-04-08 22:07 +1000
    Re: how to convert code that uses cmp to python3 Marko Rauhamaa <marko@pacujo.net> - 2016-04-08 15:52 +0300

csiph-web