Afficher un message
Vieux 17/10/2007, 11h55   #7
Juha Nieminen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Does 'if' have performance overhead

lali.b97@gmail.com wrote:
> Somewhere in a tutorial i read that if statement has performance
> overheads as code within the if statement cannot take benefit of
> pipeling of microprocessor and also that the compiler cannot
> agressively optimize that code.
>
>>From that day onwards i have been trying to avoid if statement withing

> my functions as much as possible and also try to have minimum code
> withing if block.


You are making the classic mistake: Believing something you read and
starting blindly doing it that way without actually *testing* it in
practice.

I may well be that your avoidance of the if clause may in fact be
producing slower code. However, since you haven't tested both
possibilities in your programs, you can't know.

Anyways, in the vast majority of cases such a small potential
optimization doesn't matter at all. Usually less than 1% of a program
which performs heavy calculations would require such low-level
optimization (if even that much).
  Réponse avec citation
 
Page generated in 0,04544 seconds with 9 queries