[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Patch: reducing code duplication by using functions

From: Dmitry <wipedout_at_yandex.ru>
Date: Wed, 02 Sep 2009 12:11:17 +0400

Oto BREZINA wrote:

>>> 2. using ptr[i] is faster anyway - according intel optimazition manual
>>> (at least as i remmember)
>> I though pointer arithmetic was faster - but I guess with todays
>> optimizing compilers it won't make a difference.
>I will do some test to check it, but as I rememeber it comes from
>internal cache mechanizm. So not sure if compiler is able to do such
>Also according that paper (I should probably reread it) decrementing of
>pointer takes more time - because of cache.

I've done a test - a locally allocated (automatic variable) buffer of size 2048 is processed 100 million times in a loop. First time it is referenced as buffer[i], second time there're two pointers - head set to the first element and tail set to the last, tail is decremented along the pass.

Code is compiled with VC++7, Full Optimization (/Ox), GetTickCount() is used to measure time.

The first variant takes 157375 ms, the second one - 157406 ms. They are almost equal - about 0,01% difference.

The emitted machine code is very similar - the key difference is that with buffer[i] the comparison is done by comparing a register to a constant and in the head!=tail the value to compare against (head) is first loaded from memory (the compiler fails to store it on a register). However in the latter case head is unchanged and therefore each such load results in a cache hit.

Decrementing or incrementing the buffer index or pointer used for buffer access (traversing direction) should also not result in any significant difference. The cache has no idea of what code runs in the processor core - it only works with actual memory accesses. If several subsequent accesses occur at adjacent addresses and all of them correspond to one cache line they all result in cache hits. Regardless of traversing direction once the cache miss occurs the line is fetched and several subsequent accesses result in hits.

I guess TSVN has some code that needs performance tuning. But the string processing routine we discuss here is not the number one candidate.

Best wishes.


To unsubscribe from this discussion, e-mail: [dev-unsubscribe_at_tortoisesvn.tigris.org].
Received on 2009-09-02 12:53:04 CEST

This is an archived mail posted to the TortoiseSVN Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.