05-08-2009 05:43 AM
Hi,
I was curious about the speed that the register keyword may add to my loop.
I made a trial and -surprisingly- observed that the loop completed sooner with a normal local variable.
The loop is a very simple summing loop like:
unsigned char chksum = 0;
unsigned char array[5000];
for (i=0; i<5000; i++)
{
chksum += array[i];
}
I tried this with and without specifying the chksum variable with register keyword. The result was 21 usec with normal local variable and 29 usec with register variable (!).
I know, for optimizing compilers the register keyword does not mean much since the compiler can decide which variable to be stored in CPU better than the coder.
But since CVI is not optimizing -as far as I know-, I expected that trick to work.
Any comments?
Note: I'm using CVI 8.5.1 (356) on an Intel Core2 T7200 2.0GHz CPU
05-08-2009 11:34 AM
Hello Eren,
Are you sure that the time difference that you saw couldn't be attributed to random variation? ~20 microseconds is a very small time period and I would expect random fluctuations. If you take that measurement multiple times, in both cases, and then average the results, do you still see a meaningful difference?
The reason I'm asking is because CVI doesn't actually do anything with the register keyword (other than recognizing it and not complaining about it). You're correct in that CVI is not an optimizing compiler, in which case that keyword would be meaningful. But taking up extra registers to store local variables (there aren't very many available in x86) caused several problems, and the benefits did not make up for the risks involved.
Luis
05-11-2009 01:59 PM
Hi Luis,
Thank you for your attention.
I have made further trials with 50000 iterations in a single loop and averaging 10000 loop times.
The execution time does not seem to depend on the register keyword.
Whichever loop is executed first its average time is always lower (or higher !).
Yes, it changes also from execution to execution.
I give up trying. I could not correlate the results and come up with a conclusion.
Thanks,
05-12-2009 05:55 AM