|
From: <or...@vp...> - 2003-08-04 14:20:12
|
Hi!
Now, I have a question.
I need to do heavy optimizations in the project I am working on, and I
am asking you, whether will I gain any speedup by optimizing loops. I am
interested in the for loop exactly. Let's take this example:
for(i=0;i<getint();i++){
/* ... */
}
Would it worth it to take that getint() into an outer variable, and only
use that in the conditional, like this:
int c = getint();
for(i=0;i<c;i++){
/* ... */
}
Will this give me any speedup? I am interested in particular, is for
going to call getint() EVERY time in the first case (on top), or will it
do it only once? I think the second case is better, am I right?
Allright, that was my first question, here is the second:
What is the case, if the conditional is a KNOWN value. Something, like a
macro. Here is the example:
#define GETINT (10*5)
for(i=0;i<GETINT;i++){
/* ... */
}
I suppose, this will be optimised by the compiler, and this can even be
unrolled, am I right?
Thanks in advance.
--
Greetings,
Balázs
|