Z
zaemin
From a web-site that teaches optimization for c,
I saw bellow optimization rule.
int fact1_func (int n)
{
int i, fact = 1;
for (i = 1; i <= n; i++)
fact *= i;
return (fact);
}
int fact2_func(int n)
{
int i, fact = 1;
for (i = n; i != 0; i--)
fact *= i;
return (fact);
}
The author say 'fact2_func' is faster than 'fact1_func'.
That means 'i <= n' operation is more expensive than 'i != 0'.
So far, I thought all condition statements have same cost.
So I want to know the cost of condition states from the fast one to slow one.
Can anyone tell me?
I saw bellow optimization rule.
int fact1_func (int n)
{
int i, fact = 1;
for (i = 1; i <= n; i++)
fact *= i;
return (fact);
}
int fact2_func(int n)
{
int i, fact = 1;
for (i = n; i != 0; i--)
fact *= i;
return (fact);
}
The author say 'fact2_func' is faster than 'fact1_func'.
That means 'i <= n' operation is more expensive than 'i != 0'.
So far, I thought all condition statements have same cost.
So I want to know the cost of condition states from the fast one to slow one.
Can anyone tell me?