Consider these two implementations of a function:
double MyFoo::foo(std::vector<double> & v){
double f1 = v.at(1);
double f2 = v.at(2);
double f3 = v.at(3);
double f4 = v.at(4);
double f5 = v.at(5);
double f6 = v.at(6);
double ret = sin(f1)+ sin(f2)+ sin(f3)+ sin(f4)+ sin(f5)+ sin(f6)+ sin(f7);
return ret;
}
and
double MyFoo::foo(std::vector<double> & v){
double ret = sin(v.at(1))+ sin(v.at(2))+ sin(v.at(3))+ sin(v.at(4))+ sin(v.at(5))+ sin(v.at(6))+ sin(v.at(7));
return ret;
}
Is there any noticeable difference (if any) in execution time of these functions? Do these local variable assignments introduce computational overhead or the compilers handles the useless local variables?
P.S. Choice of sin()
is completely arbitrary. My question is focused on the local variables and not the operations happening inside.