Re: [Python-ideas] [Python-Dev] Optimizing list.sort() by checking type in advance

On Mon, Oct 10, 2016 at 7:56 PM, Elliot Gorokhovsky <elliot.gorokhovsky@gmail.com> wrote:
But that's suspicious in itself -- since no comparisons are needed to sort a 1-element list, if it's still faster, there must be something else you're doing (or not doing) that's affecting the time measured. I wonder if it's the method lookup that's is slower than the entire call duration? That explains why s[:1] == 'x' is faster than s.startswith('x'), for example. A simple nit on your test code: calling time() twice per iteration could also affect things. I would just call time() once before and once after the innermost for-loops. (IIRC timeit tries to compensate for the cost of the loop itself by measuring an empty loop, but that's got its own set of problems.) Anyway, you should ignore me and listen to Tim, so I'll shut up now. -- --Guido van Rossum (python.org/~guido)

On Mon, Oct 10, 2016 at 10:15 PM Guido van Rossum <guido@python.org> wrote:
Oh, ya. Duh. So that's weird... I would very much to figure out what causes that, actually. I don't think method calling has anything to do with it, since I'm subclassing list (could be wrong though). Perhaps it has to do with the fact that my sort method is compiled on my laptop while my python is a distributed binary? I will be able to rule that out when I implement this as a patch instead of an extension module and test my own build. Anyway, thanks for looking at all this, I will post on the bug tracker and on here once I have something more mature; this feedback has been very useful.

On Mon, Oct 10, 2016 at 10:15 PM Guido van Rossum <guido@python.org> wrote:
Oh, ya. Duh. So that's weird... I would very much to figure out what causes that, actually. I don't think method calling has anything to do with it, since I'm subclassing list (could be wrong though). Perhaps it has to do with the fact that my sort method is compiled on my laptop while my python is a distributed binary? I will be able to rule that out when I implement this as a patch instead of an extension module and test my own build. Anyway, thanks for looking at all this, I will post on the bug tracker and on here once I have something more mature; this feedback has been very useful.
participants (3)
-
Elliot Gorokhovsky
-
Greg Ewing
-
Guido van Rossum