vendredi 2 octobre 2020

Performance difference between two if statements?

I asked myself if it makes a performance difference if I use an if statement with x conditions, or x if statements with only 1 condition each.

so for example:

if statement with 3 conditions:

if a == 0 and b == 0 and c == 0:
    #do something

3 if statements with just one condition each:

if a == 0:
    if b == 0:
        if c == 0:
            #do something

I think that the results of this examples will be the same, but I don't know if there would be a noticeable performance difference if a = 1. Would the program check all 3 conditions in the first example even if the first one (a is 1 not 0) is false?

Aucun commentaire:

Enregistrer un commentaire