<html><body><div><div>Hey,</div><div><br></div><div>&gt; I have been doing some performance experiments with memcmp, and I was</div><div>&gt; surprised that memcmp wasn't faster than it was in Python. &nbsp;I did a whole,&nbsp;</div><div>&gt; long analysis and came up with some very simple results.</div><div><br></div><div>Paul Svensson suggested I post as much as I can as text, as people would be more likely to read it.</div><div>So, here's the basic ideas:</div><div><br></div><div>(1) memcmp is surprisingly slow on some Intel gcc platforms (Linux)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; On several Linux, Intel platforms, memcmp was 2-3x slower than&nbsp;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; a simple, portable C function (with some optimizations).</div><div><br></div><div>(2) The problem: If you compile C programs with gcc with any optimization on,&nbsp;</div><div>&nbsp; &nbsp; &nbsp;it will replace all memcmp calls with an assembly language stub: rep cmpsb</div><div>&nbsp; &nbsp; &nbsp;instead of the memcmp call.</div><div><br></div><div>(3) rep cmpsb seems like it would be faster, but it really isn't:&nbsp;</div><div>&nbsp; &nbsp; &nbsp; this completely bypasses the memcmp.S, memcmp_sse3.S</div><div>&nbsp; &nbsp; &nbsp; and memcmp_sse4.S in glibc which are typically &nbsp;faster.</div><div><br></div><div>(4) The basic conclusion is that the Python baseline on&nbsp;</div><div>&nbsp; &nbsp; &nbsp;Intel gcc platforms should probably be compiled with -fno-builtin-memcmp</div><div>&nbsp; &nbsp; &nbsp;so we "avoid" gcc's &nbsp;memcmp optimization.</div><div><br></div><div>The numbers are all in the paper: I will endeavor to try to generate a text form</div><div>of all the tables so it's easier to read. &nbsp;This is much first in the Python dev</div><div>arena, so I went a little overboard with my paper below. ;)</div><div><br></div><div>&nbsp; Gooday,</div><div><br></div><div>&nbsp; Richie</div><div><br></div><div>&gt; Before I put in a tracker bug report, I wanted to present my findings</div><div>&gt; and make sure they were repeatable to others (isn't that the nature</div><div>&gt; of science? ;) &nbsp; as well as offer discussion.</div><div>&gt;</div><div>&gt; The analysis is a pdf and is here:&nbsp;</div><div>&gt; &nbsp; &nbsp; http://www.picklingtools.com/study.pdf</div><div>&gt; The testcases are a tarball here:</div><div>&gt; &nbsp; &nbsp;http://www.picklingtools.com/PickTest5.tar.gz</div><div>&gt;</div><div>&gt; I have three basic recommendations in the study: I am</div><div>&gt; curious what other people think.</div></div><div><br></div></body></html>