achuthpnr
November 25th, 2013, 06:24 AM
I am wondering which is the preffered way of programming in C, if one is using the same math expressions very often
1. Use the math function/expression each time
2. Precalculate the expression and store it to a variable and use the variable instead
My questions are:
1. Will there be any difference in the execution time?
2. When a call is made to a variable to which the expression is stored, is it actually calculating the expression or just retrieving the value of that expression?
I hope the questions are clear.
Thanks.
1. Use the math function/expression each time
2. Precalculate the expression and store it to a variable and use the variable instead
My questions are:
1. Will there be any difference in the execution time?
2. When a call is made to a variable to which the expression is stored, is it actually calculating the expression or just retrieving the value of that expression?
I hope the questions are clear.
Thanks.