Khookie wrote:
> "Sing" <s...@gmail.com> wrote:
>>
>> I would like to optimise a max() algo that my program uses many
>> times. Which one is faster or are they the same?
>>
>> 1. #define max(a,b) (((a) > (b)) ? (a) : (b))
>> 2. if (a>b) return a
>>
>> I have a feeling that (1) is faster, but cannot explain why. Can
>> some Gurus enlighten?
>
> i think u meant "if (a > b) return a else return b;" with no. 2.
>
> they should both compile down to exactly the same code (with or
> without optimisations). The (a ? b : c) ternary operator is a
> shortcut for "if a return b else return c;"
They should not create the same code. 2 (as modified) will exit
the function. 1 will select a value in an expression.
--
Merry Christmas, Happy Hanukah, Happy New Year
Joyeux Noel, Bonne Annee.
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from
http://www.teranews.com