Comparing strings from the back?

Neil Hodgson nhodgson at iinet.net.au
Tue Sep 4 22:18:28 EDT 2012


Roy Smith:

> I'm wondering if it might be faster to start at the ends of the strings
> instead of at the beginning?  If the strings are indeed equal, it's the
> same amount of work starting from either end.

    Most people write loops that go forwards. This leads to the 
processor designers prioritizing detection mechanisms like cache 
prefetching for that case.

    However, its not always the situation: a couple of years ago Intel 
contributed a memcpy implementation to glibc that went backwards for a 
performance improvement. An explanation from a related patch involves 
speculative and committed operations and address bits on some processors 
and quickly lost me:
paragraph 3 of
http://lists.freedesktop.org/archives/pixman/2010-August/000423.html

    The memcpy patch was controversial as it broke Adobe Flash which 
assumed memcpy was safe like memmove.

    Neil



More information about the Python-list mailing list