mercredi 14 août 2019

if-else vs Ternary function call performance

In my C++ code, I have to select between two functions that take the same arguments based on a given condition. I could write:

if (condition) 
   return foo(a, b, c);
else
   return bar(a, b, c);

Or:

return (condition? foo : bar)(a, b, c);

But which of these two ways is faster?

Aucun commentaire:

Enregistrer un commentaire