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
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].
|
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.