[Python-Dev] memcmp performance

Antoine Pitrou solipsis at pitrou.net
Fri Oct 21 18:01:45 CEST 2011


On Fri, 21 Oct 2011 08:24:44 +0200
Stefan Behnel <stefan_ml at behnel.de> wrote:
> Antoine Pitrou, 20.10.2011 23:08:
> >> I have been doing some performance experiments with memcmp, and I was
> >> surprised that memcmp wasn't faster than it was in Python.  I did a whole,
> >> long analysis and came up with some very simple results.
> >
> > Thanks for the analysis. Non-bugfix work now happens on Python 3, where
> > the str type is Python 2's unicode type. Your recommendations would
> > have to be revisited under that light.
> 
> Well, Py3 is quite a bit different now that PEP393 is in. It appears to use 
> memcmp() or strcmp() a lot less than before, but I think unicode_compare() 
> should actually receive an optimisation to use a fast memcmp() if both 
> string kinds are equal, at least when their character unit size is less 
> than 4 (i.e. especially for ASCII strings). Funny enough, tailmatch() has 
> such an optimisation.

Yes, unicode_compare() probably deserves optimizing.
Patches welcome, by the way :)

Regards

Antoine.




More information about the Python-Dev mailing list