Hello!
It seems I have some misunderstanding about some aspects of C programming or there are some compiler issues. I have a function:
Code:
double myFunction1( myData *data )
{
double result1;
/* a lot of computations here */
...
double totalResult = result1;
return totalResult;
}
I call this function in my program a lot of times. Let's say it takes 10 minutes to run the program. Now I had to make my function more complicated so I added another part and checked how fast it is. While I was testing for speed I did not added result2 to the totalResult. I was just interested how much new computations take in terms of execution time. I found out. That my program runs 15 minutes.
Code:
double myFunction2( myData *data )
{
double result1;
/* a lot of computations here !!! */
...
double result2;
/* a lot of computations here !!! */
...
double totalResult = result1;
return totalResult;
}
Then, I wrote a final version:
Code:
double myFunction3( myData *data )
{
double result1;
/* a lot of computations here !!! */
...
double result2;
/* a lot of computations here !!! */
...
double totalResult = result1 + result2; /!!!!
return totalResult;
}
...and I found out that program runs now 30 minutes!!! So the difference in execution time between myFunction2() and myFunction3() is two fold.
Why is it like this? Might it be that if I don't use result2 the compiler somehow builds executable differently? How I can improve performance in such situation?