Hello,
Let's say you have a function like this one :
To sum up, code where the same test is performed several times in a row. Now consider this function, where the test has been factorized :
My question is : is f2 always faster than f ? Or are there other considerations that i am missing ?
Thanks in advance,
Michael
Let's say you have a function like this one :
Code:
void f( int n ) {
... some code 01 ...
if( n == 3 ) {
... some code Test1a ...
}
else {
... some code Test1b ...
}
... some code 02 ...
if( n == 3 ) {
... some code Test2a ...
}
else {
... some code Test2b ...
}
... some code 03 ...
}
To sum up, code where the same test is performed several times in a row. Now consider this function, where the test has been factorized :
Code:
void f2(int n) {
if( n == 3 ) {
... some code 01 ...
... some code Test1a ...
... some code 02 ...
... some code Test2a ...
... some code 03 ...
}
else {
... some code 01 ...
... some code Test1b ...
... some code 02 ...
... some code Test2b ...
... some code 03 ...
}
}
My question is : is f2 always faster than f ? Or are there other considerations that i am missing ?
Thanks in advance,
Michael