Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'cache': 0.05; 'case.': 0.05; 'bits': 0.07; 'assumed': 0.09; 'backwards': 0.09; 'broke': 0.09; 'explanation': 0.09; 'url:2010-august': 0.09; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'loops': 0.16; 'memcpy': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'prioritizing': 0.16; 'processors': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'roy': 0.16; 'url:freedesktop': 0.16; 'wrote:': 0.17; 'intel': 0.17; 'processor': 0.17; 'contributed': 0.20; "i've": 0.23; 'patch': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'wondering': 0.26; 'ago': 0.27; 'went': 0.28; 'received:192.168.1.3': 0.29; "i'm": 0.29; 'related': 0.30; 'ends': 0.30; 'quickly': 0.32; 'received:84': 0.32; 'to:addr :python-list': 0.33; 'operations': 0.33; 'faster': 0.35; 'subject:?': 0.35; 'url:org': 0.36; 'subject:: ': 0.38; 'some': 0.38; 'instead': 0.39; 'performance': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'think': 0.40; 'lost': 0.60; 'address': 0.60; 'most': 0.61; 'safe': 0.63; 'ever': 0.63; 'adobe': 0.65; 'improvement.': 0.65; 'url:lists': 0.65; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'flash': 0.72; 'designers': 0.75; 'neil': 0.84; 'reply- to:addr:python.org': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=IekFqBWa c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=lR6CHUT36vYA:10 a=FJ6M2os8eWgA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=V6qLa7mCgSoA:10 a=niOiZsfzgBQA:10 a=iO32V2h0kgIA:10 a=KKdZbUKcWg0A:10 a=lPGR8isjMFIA:10 a=dtEgOtjo2a8A:10 a=e5mUnYsNAAAA:8 a=lREc7C4PnJBeqAs_C5MA:9 a=wPNLvfGTeEIA:10 a=RYoNdUkZldIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Wed, 05 Sep 2012 03:39:01 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:15.0) Gecko/20120824 Thunderbird/15.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Comparing strings from the back? References: <-9CdnaqjTK6NKtvNnZ2dnUVZ_gednZ2d@westnet.com.au> In-Reply-To: <-9CdnaqjTK6NKtvNnZ2dnUVZ_gednZ2d@westnet.com.au> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1346812744 news.xs4all.nl 6903 [2001:888:2000:d::a6]:44751 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:28441 On 05/09/2012 03:18, Neil Hodgson wrote: > 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. > I don't think I've ever use memcpy, only memmove.