Efficiency of Code Functionally Similar to if()
I want to know how efficient (or inefficient) if statements are to their alternatives and in what ways. I'm certain there are many alternatives I don't know---and I do want to hear about them---but in particular the following two ways.
To keep it simple, assume x is either 0 or 1 and thisFunction() does something. Before the two ways, the if statement I'll translate:
if x==1:
thisFunction()
#Code End
for i in range(x):
thisFunction()
#Code End
list=[doesNothing, thisFunction]
list[x]()
#Code End
Aside from if statement alternatives, what are ways I can compare the efficiency of two segments of code?
u/Eclipse1255 — 25 days ago